How does PHP handle sessions, and where is session data typically stored?
Last updated
session_start()reads or sets thePHPSESSIDcookie and loads the matching data into$_SESSION. PHP serializes and saves it at request end. Only the ID goes to the client.Data is stored server-side in files by default (
session.save_path). Viasession.save_handlerit can use Redis, Memcached or a database, which is needed when multiple servers share sessions.For security, call
session_regenerate_id()after login (prevents fixation) and setHttpOnly/Securecookie flags.