Unsure about login on website
<p>I have read a lot of about authentication in PHP, but I'm a litte bit obscure about it.</p>

<p><a href="http://php.net/manual/de/features.http-auth.php" rel="nofollow">php.net</a> describes to use the <code>header()</code> method i.e.</p>

<pre><code>&lt;?php

$valid_passwords = array ("mario" =&gt; "carbonell");
$valid_users = array_keys($valid_passwords);

$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

$validated = (in_array($user, $valid_users)) &amp;&amp; ($pass == $valid_passwords[$user]);

if (!$validated) {
  header('WWW-Authenticate: Basic realm="My Realm"');
  header('HTTP/1.0 401 Unauthorized');
  die ("Not authorized");
}

// If arrives here, is a valid user.
echo "&lt;p&gt;Welcome $user.&lt;/p&gt;";
echo "&lt;p&gt;Congratulation, you are into the system.&lt;/p&gt;";
?&gt; 
</code></pre>

<p>Is this best practice, or is it also standart to create an authentication with two html elements and send the login parameter by action <code>post</code> an if the login data are incorrect do a <code>header('Location: ../view/wrongLogin.html')</code> or stay on the login page <code>index.html</code>?</p>

<p>If I create two HTML tags with 'username' and 'pwd' I have to work with <code>$_SESSION['username']</code> and <code>$_SESSION['pwd']</code>. </p>

<p>By using the <code>header(...)</code> I use <code>$_SERVER['PHP_AUTH_USER']</code> and <code>$_SERVER['PHP_AUTH_PW']</code>.
Actually it is just an other way to send the login data, and an other way to make it possible, that the user enter his login data.</p>

<p>I'm totaly unsure which way I should choose!</p>