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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The events that take place when you issue session_start() in your script.

Sessions

The events that take place when you issue session_start() in your script.

by  sleipnir214  Posted    (Edited  )
Then you issue session_start() in your code, a number of things happen in quick succession:[ol 1][li]PHP determines whether session garbage-collection must take place:[/li][ol a][li]PHP divides the value of the runtime configuration setting "session.gc_probability" by the value of the runtime configuration setting "session.gc_divisor". (The default value for session.gc_probability is 1. The default value for session.gc_divisor is 100.)[/li][li]PHP generates a random number.[/li][li]If the random number is smaller than the calculated quotient, garbage-collection activates[/li][/ol][li]If garbage collection is to take place, PHP checks all files in the directory specified by the runtime configuration setting "session.save_path". It is looking for all files older than the number of seconds in the runtime configuration setting "session.gc_maxlifetime". All files older than that number of seconds are deleted.

[/li][li]PHP then checks to see whether a cookie named the same as the runtime configuration setting "session.name" was sent by the browser.[/li][ol a][li]If the cookie exists, PHP fetches the value of that cookie. That value is the current session id.[/li][li]If the cookie does not exist, PHP generates a session id and sets a cookie named as specified in "session.name". The value of that cookie is the generated session id.[/li][/ol][li]If a session cookie with a session id was sent by the user's browser, PHP will look in the directory specified by "session.save_path". It is looking for a file named "sess_" plus the session id.[/li][ol a][li]If that file is found, PHP reads the session data stored there and populates $_SESSION.[/li][li]If the file is not found, PHP initializes $_SESSION as empty[/li][/ol][/ol]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top