0

Good'ay all,

I'm looking for a method of saving a users session (I.e. automatically logging them back into the same page they logged out from).

But I have a few things to consider:

1) Will they logout or will they just close the browser? This means I can't add the process to the logout script.

2) What if they log back in on another PC? This voids the idea of using cookies.

3) Sessions just won't do the trick imo?

Suggestions? I'm currently considering a SQL query that's executed with the path to the current file at the start of every page and storing it against their name in SQL, then calling on it when they log in. I'm not here for the code just the best method and some insight :)

Any recommendations would be welcomed with open arms :) In the mean time I'm going to flip around google looking for inspiration :3

4
Contributors
5
Replies
27
Views
4 Years
Discussion Span
Last Post by mmcdonald
1

1) Will they logout or will they just close the browser?

They will close the browser, but you can still trap that with Javascript.

0

They will close the browser, but you can still trap that with Javascript.

I had no idea you could detect and act upon a browser close in JavaScript! Thank You!! :D

Edited by mmcdonald

1

Some php/js:

<?php if(isset($_SESSION['login'])){ ?>
<script>
window.onbeforeunload = function()
{
  return confirm('Please logout before closing the browser ?');
}
</script>
<?php } ?>

Something like that in your head area. You could hijack the confirm return value (true) to logout (ajax) the user.

Edited by diafol

0

Thanks diafol, I've already found and added the code. It works great, but your suggestion was still really appriciated. Thank you :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.