Forum Moderators: coopster
<?php
session_save_path('/usr/local/home/scoe/www/tmp');
// include function files for this application
session_start();
include_once ('../php_fns/lions_sc_fns.php');
ric_session_check();
$old_user = $HTTP_SESSION_VARS['ric_user']; // store to test if they *were* logged in
unset($HTTP_SESSION_VARS['ric_user']);
session_destroy();
// start output html
do_ric_style();
if (!empty($old_user))
{
echo 'Logged out.<br />';
do_html_url('index.php', 'Login');
}
else
{
// if they weren't logged in but came to this page somehow
echo 'You were not logged in, and so have not been logged out.<br />';
do_html_url('index.php', 'Login');
}
?>
Now this seems to remove session data when they log out. However, it doesn't execute when they just click the little x in the top right corner and close the window. How do I destroy the session when they close the window?
--Nick
function getWindowLogout()
{
if(window was closed)
call php logout function
else
do nothing
}
and then include the file where the function lies, on every page (ie. include_once('../php_fns/javascript/<filename where I store said function>))
Like that? Then where do I call it or do I just put it at the top of every page or something?
--Nick
function killSession() {
// call logout.php
}
window.onunload = killSession;
BUT: that way the user would be logged out also when browsing to another page in the same window. You might need to use frames to work around that problem (like my internet bank does). The main frame contains the actual content. The fixed top frame contains the onunload handler. The onunload handler spawns a tiny new window that calls the logout script and closes itself when done.
Sessions, javascript, frames, popups: brrrr... :)