title: HTTP authentication PHP and HTML form
body: <p>Good morning! I have some problem with HTTP authentication with PHP. As I found in different posts, after the form's submit I tried this PHP code:</p>
  
  <p><strong>PHP</strong> </p>
  
  <pre><code>&lt;?php 
  $us = 'name';
  $pswd = 'pass';
  function verify($a, $b) { return ($a==$us &amp;&amp; $b==$pswd);};
  $user = $_SERVER['PHP_AUTH_USER'];
  $password = $_SERVER['PHP_AUTH_PW'];
  if(!isset($user) || verify($user, $password)==false) {
      header('WWW-Authenticate: Basic realm="MyRealm"');
      header('HTTP/1.1 401 Unauthorized');
      exit;
  }
  else{
      echo 'Correctly authenticated';
  }
  ?&gt;
  </code></pre>
  
  <p>When I click the submit botton form from HTML a popup appears asking me (again) username and password. Why? I think that in some ways I've to set the PHP_AUTH_USER in $_SERVER with the value in the input, but I don't know how.<br>I think that I've done a mistake when I send the data from the form because I'm still using the post method. What method I have to use?</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;br&gt;
  &lt;form method="post" action="page.php"&gt;
     &lt;input type="text" name="user"&gt;
     &lt;input type="password" name="password"&gt;
     &lt;input type="submit"&gt;
  &lt;/form&gt;
  &lt;br&gt;
  </code></pre>
  
  <p>I never did it before, any tips on how check data on server side or something else are welcome!</p>