Hi guys, I have a very simple password set up on a webpage of mine, written in PHP. I have a "checkpass.php" page that checks to see if a $_POST value is the correct password. If so, it set the $_SESSION['logged'] variable to "YES", and then moves on to the next page. Every page from then on checks to see if $_SESSION['logged'] is YES, and so on. Here's the code for the main pages:
index.php:
checkpass.php:
and finally, current.php:
So, index passes the user-inputted password to checkpass, which then sets the $_SESSION['logged'] variable to "YES", and redirects to current.php, which is the "main" page. For some reason though, even though logged was set to "YES," the current.php page redirects to apple.com, indicating a problem with the password. I've been reading about session variables for the past couple days, and I have no idea what I'm doing wrong!
Any help would really be appreciated!
index.php:
Code:
<?php
session_start();
echo "Password: <form action='checkpass.php' method='post'><input type='text' name='pass' id='pass'><input type='submit' value='Login'></form>"
?>
checkpass.php:
Code:
<?php
session_start();
session_register('logged');
$pass = $_POST['pass'];
if ($pass == "123pass") {
$_SESSION['logged'] = "YES";
header("Location: http://www.craigotis.com/iou/current.php");
}
else {
$logged = "NO";
header('Location: http://www.apple.com');
}
?>
and finally, current.php:
Code:
<?php
session_start();
if ($_SESSION["logged"] == "YES") {
echo "Login successful";
}
else
header("Location: http://www.apple.com");
?>
So, index passes the user-inputted password to checkpass, which then sets the $_SESSION['logged'] variable to "YES", and redirects to current.php, which is the "main" page. For some reason though, even though logged was set to "YES," the current.php page redirects to apple.com, indicating a problem with the password. I've been reading about session variables for the past couple days, and I have no idea what I'm doing wrong!
Any help would really be appreciated!