sngumo Posted July 23, 2009 Share Posted July 23, 2009 Hi, I would like to be helped with AJAX code which will enable me to configure an atuo logout feature in my site such that the user is logged out (after xxmins) regardless of whether the user clicks the page later or not i.e. the user will return and find he has been logged out. I have already written the PHP code and I dont know enough AJAX to configure the rest. Please assist. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/ Share on other sites More sharing options...
dzelenika Posted July 23, 2009 Share Posted July 23, 2009 You don't need ajax for this. Javascript function setTimeout() should be enough. Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-881068 Share on other sites More sharing options...
sngumo Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks dzelenika for your reply, but the PHP login code involves making correspondent entries into the site's MYSQL database and thus when the auto logout occurs that information must be saved on the database (i.e. time of logout). Now the PHP code for recording this info is already there, now what I wanted is additional code which will enable the logout to happen automatically without anyone having to click the page i.e. if the user returns, he will find himself logged out. Thanks again for the reply Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-881806 Share on other sites More sharing options...
dzelenika Posted July 24, 2009 Share Posted July 24, 2009 Thanks dzelenika for your reply, but the PHP login code involves making correspondent entries into the site's MYSQL database and thus when the auto logout occurs that information must be saved on the database (i.e. time of logout). Now the PHP code for recording this info is already there, now what I wanted is additional code which will enable the logout to happen automatically without anyone having to click the page i.e. if the user returns, he will find himself logged out. Thanks again for the reply I think this is what you are looking for: <script type="text/javascript"> var t=setTimeout("document.location=\"logoutPage.php\"",3600000); </script> In logoutPage you can log any information or do whatever you want without any click Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-881861 Share on other sites More sharing options...
cpd Posted July 25, 2009 Share Posted July 25, 2009 that will log him out regardless. you need a way of canceling the timer. <body onLoad="startTimer();" onMousOver="stopTimer();" onMouseOut="startTimer();"> <!-- Your code --> </body> and then for the javascript something like <script type="text/javascript"> var t; function startTimer(){ t=setTimeout("document.location='logout.php'", 600000); } stopTimer(){ clearTimeout(t); } </script> its just a suggestions, im not actually great with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-882566 Share on other sites More sharing options...
Third_Degree Posted July 25, 2009 Share Posted July 25, 2009 I'm not sure of your code so this might not work, but why not update the time of log out when the user logs in, then make the cookie(s) expire after whatever time you choose? If the user logs out before the anticipated time, no worries, you just update the table anyway. If your goal here though is to physically remove their logged in page from the browser, i understand why wouldn't want to do this. Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-882864 Share on other sites More sharing options...
vikaspa Posted August 13, 2011 Share Posted August 13, 2011 I found this code most useful ... however, can we display countdown time ... please help Quote Link to comment https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-1256792 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.