Hello, I believe my code is correct although I'm not getting the result I desire. Heres a breakdown of my code so far...
Password.php
<?php
// if POST
// get contents of a file into a string
$filename = "pass.txt";
$file = fopen($filename, "r");
$filesize = filesize($filename);
$text = fread( $file, $filesize);
fclose($file);
if (isset($POST['Password']))
{
if($POST['Password'] == "$text")
{
setcookie("uname", $name, time()+36000);
header('Location: admin.php');
} else {
echo "Nope not correct";
}
}
// display form:
else {
?>
<form action="<?php htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES); ?>" method="POST">
Enter your password: <input type="password" name="Password" />
<input type="submit" />
<?php } ?>
Start of my admin page....(admin.php)
<?php
if (isset($COOKIE["uname"]))
echo "Welcome " . $COOKIE["uname"] . "!<br />";
else
header("Location: password.php");
?>
Now basically want I need is for the user to fill out his or her passowrd on the login box. This would then check if it is correct and assign a cookie. The admin page would then check if they have this cookie and redirect them back to login if they havent. So far that hasnt happened. So what am i doing wrong?