Where are $_SESSION variables stored?

php

Question

Are $_SESSION variables stored on the client or the server?

1
152
12/27/2016 3:07:08 AM

Accepted Answer

The location of the $_SESSION variable storage is determined by PHP's session.save_path configuration. Usually this is /tmp on a Linux/Unix system. Use the phpinfo() function to view your particular settings if not 100% sure by creating a file with this content in the DocumentRoot of your domain:

<?php
    phpinfo();
?>

Here is the link to the PHP documentation on this configuration setting:

http://php.net/manual/en/session.configuration.php#ini.session.save-path

157
10/7/2017 11:49:04 AM

As mentioned already, the contents are stored at the server. However the session is identified by a session-id, which is stored at the client and send with each request. Usually the session-id is stored in a cookie, but it can also be appended to urls. (That's the PHPSESSID query-parameter you some times see)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon