I could not find on the web a complete solution for this task.
This is not the perfect solution, because it's doesn't have the
ability to log the logout if browser crash or user leave it open while
the session time out expires.
So, any improvement would be apreciated.
1. Make the system frameable, by creating a frameset page with an
unique frame - the system. So the user could navigate through the
pages without "leave" the website.
<frameset rows="*" framespacing="0 " border="0"
onunload="unloa dLogOut();">
<frame id="fmeSys" name="fmeSys" src="index.php" frameborder="0"
scrolling="auto " />
</frameset>
2. Save this frameset page (default.html). Note the onunload event of
frameset object. It calls the following function.
<script language="javas cript">
function unloadLogOut() {
var xmlHttp;
try {
// Firefox, Opera 8.0 , Safari
xmlHttp = new XMLHttpRequest( );
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
} catch (e) {
return false;
}
}
}
xmlHttp.open("G ET","logout.php ",true);
xmlHttp.send(nu ll);
}
</script>
3. The logout.php script is where you update the logout time and
session_destroy ().
mysql_query("UP DATE log SET dt_logout = NOW()
WHERE id_user = $_SESSION[id_user]
AND id = $_SESSION[id_access]");
session_destroy ();
Best regards,
Thiago
This is not the perfect solution, because it's doesn't have the
ability to log the logout if browser crash or user leave it open while
the session time out expires.
So, any improvement would be apreciated.
1. Make the system frameable, by creating a frameset page with an
unique frame - the system. So the user could navigate through the
pages without "leave" the website.
<frameset rows="*" framespacing="0 " border="0"
onunload="unloa dLogOut();">
<frame id="fmeSys" name="fmeSys" src="index.php" frameborder="0"
scrolling="auto " />
</frameset>
2. Save this frameset page (default.html). Note the onunload event of
frameset object. It calls the following function.
<script language="javas cript">
function unloadLogOut() {
var xmlHttp;
try {
// Firefox, Opera 8.0 , Safari
xmlHttp = new XMLHttpRequest( );
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
} catch (e) {
return false;
}
}
}
xmlHttp.open("G ET","logout.php ",true);
xmlHttp.send(nu ll);
}
</script>
3. The logout.php script is where you update the logout time and
session_destroy ().
mysql_query("UP DATE log SET dt_logout = NOW()
WHERE id_user = $_SESSION[id_user]
AND id = $_SESSION[id_access]");
session_destroy ();
Best regards,
Thiago
Comment