Page 1 of 1

php log in and log out procedure?

Posted: Wed Dec 10, 2008 6:31 pm
by djcrisp
anyone know how can i make sure that the user is logged in? and how do i create a logout procedure? also if user hits the back button, it should log them out. how can i go about doing this? any modifications, any help is greatly appreciated.

thanks in advance :-)





Please enter username and password:</br>
<form method="post" action="asif.php">
Username: <input type="text" name="username" size="20"></br>
Password: <input type="password" name="password" size="20"></br>

<input type="Submit" value="Submit">
</form>
</body>
</html>

<?php }else{
$username=$_POST["username"];
$password=$_POST["password"];
$email=$_POST["email"];
session_start();
if ($username=="test" AND $password=="test"){ $permission="yes";}
if ($username=="test" AND $password=="school"){ $permission="yes";}

$username=$_POST["username"];
session_register("permission");
session_register("username");

if ($permission=="yes"){
?>



<?php }else{ ?>

Error in username or password
<?php } ?>

Re: php log in and log out procedure?

Posted: Wed Dec 10, 2008 8:19 pm
by watson516
Next time you post code, instead of increasing the size, there are these little wonderful tags supplied by the forum. [code =php][/code ]

As for the login/logout. You could use SESSION variables to store login details after successful login. When the user logs out, you can just change the values of the session variables. As for the back button, you could probably store the current page in a session variable and then check it whenever a page loads. If you have links on the logged in page, you could put some sort of flag in the url unless you only have a single page that the user stays logged in.

Code: Select all

session_start();
...
if($_SESSION['page']==$_SERVER['PHP_SELF'])
{
   if(userLogin($username,$password)
   {
       $_SESSION['user']=$username;
       $_SESSION['page']=$_SERVER['PHP_SELF'];
       header('Location: admin.php');
   }else{
       header('Location: login.php?error=fail');
   }
}else{
   $_SESSION['user']="GUEST";
   $_SESSION['page']=$_SERVER['PHP_SELF'];
}

Something like that maybe?