Jump to content

How a php session know when the browser closed


deepPHP

Recommended Posts

hi there,

A PHP session destroyed when a user is ask for this(logout for instance) and when I closed my browser the session destroy.

 

how the php session know if the browser closed or not and how this process have done.

 

 

thank

Link to comment
Share on other sites

Session don't die when you close the browser, they expire after a period of inactivity.

so let me ask another question to understand that, how the web server checks if session is inactive?(time-stamp doesnt could solve that because it depends on

exact specific time.. i mean i dont know how, but right after I close my browser all the sessions go away - is it happens in the client-side(browser) or the server-side?)

 

thank you very much!

Link to comment
Share on other sites

A user is linked to a session using a cookie. The cookie only contains a hash, which can be used to look up the file containing the serialized session data, generally in /tmp. When your browsers closes it will delete the cookie, therefore the user's session is lost. However the file in /tmp containing the actual session data will remain there until it's expired, and subsequently PHP has cleaned it up.

Link to comment
Share on other sites

There are two parts to an active session:

 

1) A data file stored on the server containing all the variables and their values and

2) A cookie stored on your computer which identifies which datafile to use by means of a unique hash value.

 

 

Because both parts are necessary for the session to work, a session can expire in one of two ways

 

1) Your browser forgets the cookie or

2) The server deletes the data file.

 

 

When you close your browser, you are causing the expiration via option #1. Your browser will delete it's cookie containing the hash, thus breaking the reference to the data file and killing the session. The data file will remain on the server until it gets cleaned up later by an automated process.

 

Option #2 happens if you stay idle for an extended period of time. On the server-side, all the session files are occasionally checked to see how old they are (based on last time of access). If they were last accessed more than a set amount of time ago, they are deleted. This is what causes the session to expire if you stop surfing the website for an extended period of time, but never actually close the browser.

Link to comment
Share on other sites

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.