Here's some more elaborate code you can test (basically an extension of Phil's).
test_1.php:
echo '<form action="test_2.php" method="post">';
echo '<input type="text" name="password" value="letmein" />';
echo '<input type="submit" name="submit" value="submit" />';
echo '</form>';
test_2.php:
if (isset ($_POST['submit'])) {
if ($_POST['password'] == 'letmein') {
setcookie('loggedin', 'user access');
header('Location: test_3.php');
} else {
header('Location: test_4.php');
}
} else {
header('Location: test_1.php');
}
test_3.php:
echo 'test_3.php' . '<br />';
echo '$_COOKIE[loggedin]: ' . $_COOKIE['loggedin'];
test_4.php:
echo 'test_4.php' . '<br />';
echo 'no cookie';
Of course, it could be consolidated into fewer files, and you'd need to add your validating code, etc. But it's one way you might do it.