how to automatically logout when close the browser in php?

Hi,
I would like my user to automatically logout when he's closing his browser.  How can I do that.


thanks
vn4phuongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongjunCommented:
User will auto logout when he closes his browser. Session will be lost.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vn4phuongAuthor Commented:
i am using cookies
0
hongjunCommented:
Cookies will also be expired.
By default, it will kill itself when browser is closed unless you specify it to specify at a specified number of days later.


hongjun
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jessegivyDeveloperCommented:
Why cookies?  My temporary internet files folder is already cluttered with all those little images you force me to download.

~Happy User

...sorry, just looking for interesting conversation.  Seems like the honorable hongjun has this one under control.  As an option you can manually kill the session, but as was stated above, it's really not an issue, I have however heard that when many of the larger banks delete financial records from the disk, they write the physical addresses to binary zeros seven times, what's the point of that?  Anyway, in jsp, I'm fairly sure it's:

session.destroy()

...but, unfortunatly, my memory isn't what it used to be so there may be other scenarios to consider, here's a link that says you should unregester your variables before doing so, uh I dunno if that's actually necessary
http://www.webdeveloper.com/forum/showthread.php?t=15675

Cheers,

JI
0
vn4phuongAuthor Commented:
function do_whatever()
{

       delete_cookie ( "viet1800" );




 


}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}



</script>
</head>
<body onUnload="do_whatever()">

</body>
</html>

how come this code doesn't delete the cookies?

Thanks
0
liviutudorCommented:
you need to set the cookie time to -1 -- which means cookie is deleted when the browser window is closed!
secondly, have an onunload handler on your document as suggested above which calls the function that you want to expire the session.
0
hoppercjCommented:
The Unload event only fires immediately before an object is unloaded. Objects are not unloaded when you close your browser window. The BODY Unload event would fire when you browse off to another page.

I suggest you do what is being suggested by 'liviutudor' and set the cookie to expire when the browser session is over (when all browser windows are closed).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.