note 32646 added to function.session-destroy
| From: | YAVUZ at rack1 dot php dot net | Date: | Tue, 03 Jun 2003 19:13:12 +0000 |
| Subject: | note 32646 added to function.session-destroy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49647@lists.php.net to get a copy of this message | ||
I have been trying to get people automatically logged out
and destroy the cookie with....
session_start();
$_SESSION = array();
$success = session_destroy();
if ($success) {
echo "<h2>You have been sucessfully Logged Out.<br>";
echo "Thank you for using......</h2>";
echo "<h2><a href=\"../index.html\">Login
Again?</a></h2>";
}
However, there some occassions that i could not control...
1. The user leaves w/o loggingout.
2. The user closes the browser window w/o loggingout.
3. The user loggs out but since session is set to
function StartSession()
{
session_cache_limiter("private, must-revalidate");
session_start();
}
It will restart an empty session (with no $params set).
This makes it hard for me to keep track of all these sessions
in the temp folder.
I found a solution by combining frames and Javascript.
At my top frame (which is only 1 pixel high) I entered this code...
<?php
$scripts="<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function openNewWindow(url,winName,winParams) {
var theWindow = window.open(url,winName,winParams);
if (theWindow) {theWindow.focus();}
}
var loggedin=false;
var loggingout=false;
function logOut(){
if(loggedin && !loggingout) {
openNewWindow('logout2.php', 'LogOutWin',
'width=340,height=235,status=0,menubar=0');
void('');
}
else if(!loggedin && !loggingout) {
openNewWindow('logout3.php', 'LogOutWin',
'width=340,height=235,status=0,menubar=0');
void('');
}
}
window.onunload = logOut;
//-->
</script>";
echo $scripts;
?>
This will take care of problem 2 and 3.
I had to create 3 logout.php s to deal with each situation(Different messages to user).
However, they all have the session_destroy() method at the top of this page.
The only thing I needed to my Page class was...
to add a small javascript section to log them out and
to trak the users that they are logged in or logging out.
if (isset($_SESSION["valid_user"]))
$valid_user = $_SESSION["valid_user"];
$company = $_SESSION["company"];
echo "You are logged in as: $valid_user from $company.\n";
echo "<a href=\"javascript:parent.parent.location='../class/logout.php';
parent.frames[0].loggingout=true;\">Log Out</a>\n";
echo "<script language=\"JavaScript\"
type=\"text/javascript\">\n"
."<!--\n"
parent.frames[0].loggedin=true;\n"
."//-->\n"
."</script>\n\n";
}
----
Manual Page -- http://www.php.net/manual/en/function.session-destroy.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32646
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32646&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32646&report=yes