Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-881806
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-881861
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-882566
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/167101-ajax-php-auto-logout/#findComment-882864
Share on other sites

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.