How does PHP handle sessions, and where is session data typically stored?

Last updated 15 June 2026

  • session_start() reads or sets the PHPSESSID cookie 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). Via session.save_handler it 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 set HttpOnly/Secure cookie flags.

  • https://domainindia.com/support/kb/master-php-sessions-with-ease-a-comprehensive-developers-handbook
  • https://github.com/interviewplus-ai/php-interview-questions-and-answers/
  • https://www.geeksforgeeks.org/php/php-sessions/
All PHP interview questions