Current location: Hot Scripts Forums » Programming Languages » PHP » Log out when browser is closed


Log out when browser is closed

Reply
  #1 (permalink)  
Old 07-17-07, 10:54 AM
ELV1I2's Avatar
ELV1I2 ELV1I2 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: BA
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes Log out when browser is closed

I think that I'm understand phenomena called session (PHP 4.4.2). After successfully login there is user name and password reachable by $_SESSION...
For security reason it's smart to do unlogin or log out on computer, especially when it's a one on public place in order to suppress unwanted access to your information after you leave computer without log out option.
Is there some mechanisms that could log out user when he/she close web pages without prior log out? Javascript or so..?
Thanks.
__________________
There are 3 kind of enemies: my enemies, enemies of my friends and friends of my enemies.
Reply With Quote
  #2 (permalink)  
Old 07-17-07, 04:03 PM
mgfca mgfca is offline
Newbie Coder
 
Join Date: Jul 2007
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
When browser is closed the session is lost...when you open browser again the session is a new one...
The only situation someone would open the browser and find someone else's account logged-in is when you use cookies (its recommended users only use cookies on their own computer) thats why many login forms have the "remember me" option at login
Reply With Quote
  #3 (permalink)  
Old 07-18-07, 11:05 AM
ELV1I2's Avatar
ELV1I2 ELV1I2 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: BA
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Almost true

I don't agree with you at all...session is lost when a user closed browser. But in browser that support tabs many user simply close the unwanted tab without prior logout and session is still there! Anyone who has access later to this computer could misuse remained session of previous user, isn't?
__________________
There are 3 kind of enemies: my enemies, enemies of my friends and friends of my enemies.
Reply With Quote
  #4 (permalink)  
Old 07-18-07, 11:34 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Closing a tab in a browser does not close the browser. It is necessary for the whole browser to be closed and this only applies if the session cookie has a zero lifetime.

It "should" be possible to use an onUnload event to request a url on your server that signals that someone has left a page, however I don't think this applies when a browser is actually closed (someone correct me if I am wrong.)

You cannot control how a user leaves his computer sitting when he is not there. If they login to your site and leave that page open in their browser and get up and someone else sits down and starts making changes... that is really their problem and you can not even detect that anything like this has occurred.

Likewise, if someone has a key logger/virus on their computer and their login name and password has been captured... that is really their problem and there are only limited things you can do to detect if someone else is logging in using their name and password.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 07-18-07, 02:36 PM
ELV1I2's Avatar
ELV1I2 ELV1I2 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: BA
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow

Your story is very wise mab, I appreciate it. All what you say is true, that's sure, but I remember of my apps for WIntel platform where 2/3 of whole code is dedicated to suppress a user not to press this one or this one... just 1/3 is usefully code
I thought that maybe is some simple methods for this purpose but as you said already, like for credit card PIN code, for log out process is responsible only a user, no one other. Thanks for your opinion.
__________________
There are 3 kind of enemies: my enemies, enemies of my friends and friends of my enemies.
Reply With Quote
  #6 (permalink)  
Old 07-19-07, 11:59 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Here is some tested code that works in IE7 that requests a url when you navigate away from a page or close the browser -
PHP Code:

<html>

<head>

<script type="text/javascript">
function mymessage()
{
<?php
  
// this is PHP... so that you could form a url of your choice with parmaters... as needed
  
echo "  location.href=\"closed.php\"";
?>
}
</script>
</head>

<body onunload="mymessage()">

<p>time() will be written to a file when you navigate to a different url or close the browser (at least for IE7)</p>
</body>

</html>
The closed.php code in the location.href="..." statement -
PHP Code:

<?php

// note if you attempt to navigate to a different url, you will see the following echo
// if you close the browser, there is no browser to display this, but this page is requested and executes
echo "the user navigated to a different page or closed the browser";

$handle fopen("log.txt""a");
$somecontent time() . "\r\n";
fwrite($handle$somecontent);
fclose($handle);

// in real life going to this page will prevent a person from directly navigating
// away from your page, you would need to see if you can capture the url they
// entered and then redirect to that page.
?>
But this is only an example that demonstrates that it is possible to use the onunload event.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to pharse a log but fgets not seeing new line scott2500uk PHP 9 06-12-07 02:39 AM
Setting browser to resize and remove tools, scrolling etc. Tonio9 JavaScript 3 05-02-07 03:42 PM
redirect - firefox browser chrisrobertson JavaScript 3 05-12-06 05:37 PM
Merging log files SicRob007 PHP 3 03-31-05 03:27 PM
any suggestion...open another browser? aspuser25 ASP 4 08-25-04 12:59 AM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.