Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find out the end of session

Status
Not open for further replies.

shaddow

Programmer
Joined
Mar 22, 2001
Messages
1,862
Location
RO
Is there a way to find out when a user closes his browser window?
I want to knw when a user ends his session.
Using ASP is easy to do this but dont knw any solution on PHP

________
George, M
 
php is executed before being sent to the browser, to do what you want, you have to use a client-side language. I know you can detect the closing with javascript. Maybe you could cancel it closing and redirect to a php page which will then do what you want and close.
 
Kemp hit it on the head, but what you need to keep in mind when doing this is that you're not guaranteed it will work. Only a hand full of people browse with Javascript off but if there's incentive to turning it off, more people will.

By the by, ASP can't do this by itself either, I'm assuming there you're using it with VBScript, which only works in IE... depending on your targetted audience this could have unexpected results as well.

-Rob
 
ASP can do this on server side if you didnt knw, i'm using both PHP and ASP.
On ASP when a web client leaves i get an Session OnEnd event on global.asa


________
George, M
 
I stand corrected.

Sorry if this isn't the right forum, but a quick google isn't helping. Do you mean to say that ASP opens persistent connections between a browser and the server? Or there's some kind of built in time out which it checks against? Is this method shown to be Cross-Browser/Platform (client side obviouslly) compatible?

-Rob
 
IIS(ASP) it has some built in functions but it uses cookies to store client session ID and then it uses this ID to check what it's stored in session also it checks whenever the client is still logged or not automaticaly, i cant do that in php it seems and therefor i cant check if a conexion is alive

________
George, M
 
And to mention that ASP session is same as PHP session - Cross-Browser/Platform the diference is that ASP checks if the conexion it's alive or at least he knws when a client leaves connexion.

________
George, M
 
I found session_set_save_handler()
I think this might solve the problem. Doing some research now.


________
George, M
 
There is no deterministic way to know when a browser is closed. It is possible, through the use of cookies that expire on browser closing, that the browser was once closed and has been reopened. Even the VBScript/ASP function you're talking about doesn't work for all versions of IE, much less other browsers.

session_set_save_handler() merely gives you a method of overriding PHP's method for storing and recalling session information.

For an example of the use of session_set_save_handler(), see my faq in this forum, faq434-2037, "Using MySQL to store PHP session variables"

Want the best answers? Ask the best questions: TANSTAAFL!
 
Some thoughts:

1. HTTP itself is not a stateful protocol. Client and server "hang up" once the "call" is finished. The HTTP server cannot know how long the client is actually holding on to the receiver - and it doesn't care.

2. The server can remember that he's spoken to a specific client and recall stored values. However, the client still provides a reference (session id) upon a new call.

3. Any "live" connection uses something else than basic HTTP, maybe HTTPLayer, some Java applet that has a persistent connection etc.

I strongly doubt that ASP can detect when the client closes the browser.
 
DRJ478 did you ever used ASP?
global.asa file can contain
Session_OnEnd and Session_OnStart same for Application...

Either if it's an persistent conexion or not IIS knws when an client it's off using the Session timeout. so at least i knw that after a time... i havent see such a thing on PHP maybe i need to implement the timeout myself better then let the system do that.
Not many can acces the server and do that automaticaly.
At least Apache could timeout those conexion and let me knw when a session is off.
Doing that myself is kinda offhand.

You can only see the diference between PHP and ASP by doing same thing on boths scripts. And belive me they have weak parts and strong parts.




________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top