Jump to content

[SOLVED] Session doesnt work...


gtal3x

Recommended Posts

Ok here is my script, when you go to the page it should check if the seesion is not registred and display the login form, else it should echo "You are logged in" for some reason it doesnt work and am gettin confused coz its a simple script!

<?php
$username = "alex";
$password = "mypass";
$submit = $_POST['submit'];
$post_user = $_POST['username'];
$post_pass = $_POST['password'];
if (isset ($submit)) {
if (($username != $post_user) || ($password != $post_pass)) {
	$error .= "<b>Login Failed.</b>";
}
if (!$error) {
	session_register("post_user");
	header("location:index.php");
}
else {
echo $error;	
}	
}
if (!session_is_registered("post_user")){
?>
<html>
<head><title>Admin Page</title></head>
<body>
<form name="login" method="POST" action="<?php echo $PHP_SELF; ?>" >
<table>
<tr><td colspan="2"><h1>Admin login:</h1></td></tr>
<tr><td><b>Username:</b></td><td><input type="text" name="username"></td></tr>
<tr><td><b>Password:</b></td><td><input type="password" name="password"></td></tr>
<tr><td><input type="submit" name="submit" value="Login"></td></tr>
</table>
</form>
</body>
</html>
<?php
}
else {
echo "You are Logged in!";	
}
?>

Link to comment
https://forums.phpfreaks.com/topic/79777-solved-session-doesnt-work/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.