student101 Posted August 20, 2009 Share Posted August 20, 2009 How to code in the event of a PC crash or power out or closing the browser(any)? Users login one at a time; A User logs in => The DB value (loggedin) is set to 'Y' The User makes changes.... The User Logs out => The DB value (loggedin) is set to 'N' (not logged in) Other users can now login. What if the users PC crashes or there's a Power out or even closing the browser(any)?? The user didn't click Logout!, other users can't login The DB value (loggedin) is still 'N' CREATE TABLE `tbladmin` ( `id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(15) NOT NULL DEFAULT '', `password` VARCHAR(15) NOT NULL DEFAULT '', `loggedin` VARCHAR(2) NULL DEFAULT 'N', `logdate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`adminid`) ) The only idea that came to mind was to have this above, other than, clueless. Any ideas? Quote Link to comment Share on other sites More sharing options...
student101 Posted August 23, 2009 Author Share Posted August 23, 2009 Here is a working solution for IE only! window.onbeforeunload = confirmExit; var aClick=false; function confirmExit(e) { if(document.all)e = event; if(!e)e=window.event; if (e) { if(aClick==false && (e.target==document || e.clientX<0 || e.clientY<0)) { //alert("Loggined out..."); //remove don't want an alert box! // add your server call to logout the user ajaxCall(open_win()); function open_win() { ajaxCall("http://example.com/logout.php"); //or you could call a popup; window.open("http://example.com/logout.php"); //actually irritating! } function ajaxCall(dname) { var xmlDoc; if (window.XMLHttpRequest) { xmlDoc = new window.XMLHttpRequest(); xmlDoc.open("GET", dname, false); xmlDoc.send(""); //alert(xmlDoc.responseText); //removed due to blank alert box! //return xmlDoc.responseXML; //removed, no clue why! } // IE 5 and IE 6 else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(dname); //alert(xmlDoc.responseText); //removed due to blank alert box! //return xmlDoc; //removed, no clue why! } //alert("Error loading document"); //removed due to blank alert box! return null; } } } } Quote Link to comment Share on other sites More sharing options...
student101 Posted August 26, 2009 Author Share Posted August 26, 2009 Anyone able to assist? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.