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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.