View Full Version : code for logout page using sessions
zee000
02-12-2010, 02:32 PM
hiiiii
i need a code for logout page using sessions or any other in php
any suggestions are accepted...
Schmoopy
02-12-2010, 03:10 PM
Completely depends on how you have your login set up / what sessions you use, but you could have:
<?php
if(isset($_GET['logout']) && $_GET['logout'] == 1) {
unset($_SESSION['login_details']);
}
?>
This would work if you had an array like:
Array ( [login_details] => Array (
[username] => 'Schmoopy'
[name] => 'Jack'
[more_stuff] => 'random'
) )
etc..
So it would get rid of all that information. So when you check for the "login_details" array, it won't be there, meaning the user is not logged in.
fileserverdirect
02-12-2010, 04:10 PM
Or if your using session_start();
<?php
//logout.php
session_start();
session_destroy();
header("location: HOMEPAGE_GOES_HERE.php");
?>
Schmoopy
02-12-2010, 04:55 PM
But remember using session_destroy will get rid of all the session variables, so if you have any you want to keep hold of for a different part of the site, then use unset so you don't affect them.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.