To avoid some Notice errors and other bugs:
<?php
$na = isset($_POST['na']) ? $_POST['na'] : false;
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : false;
$submit = isset($_POST['submit']) ? true : false;
if ($submit) {
if ($na == 'admin' && $pwd == 'zucker') {
header("location:first.php");
exit(); // Make sure nothing else gets sent
} else {
header("location:index.php?msg=enter correct user name and password");
exit(); // Make sure nothing else gets sent
}
}
?>
Here's a slightly more advanced example:
<?php
$na = isset($_POST['na']) ? $_POST['na'] : false;
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : false;
$submit = isset($_POST['submit']) ? true : false;
// Accounts array (append as you wish)
$accounts = array(
'admin' => '4635c0015b2084afcc7cb39593545e06',
'foo' => '37b51d194a7513e45b56f6524f2d51f2'
);
// form complete?
if ($submit && $na && pwd) {
if (isset($accounts[$na]) && md5($accounts[$na]) == $pwd) {
header("location:first.php");
exit(); // Make sure nothing else gets sent
} else {
header("location:index.php?msg=enter correct user name and password");
exit(); // Make sure nothing else gets sent
}
}
?>