--- title: Sessions --- ## Sessions Sessions are a feature in PHP that allow you to store data server side about a user. When a session is setup, a browser cookie is set which identifies the user to PHP so the PHP knows which server side variables to access. ### Starting A Session On every page you want to access the session you will need to start (or load) the session. To do so run the `session_start()` function which loads the PHP Session System. ```PHP = $expireAfterSeconds){ //User has been inactive for too long. //Kill their session. session_unset(); session_destroy(); } } //Assign the current timestamp as the user's //latest activity $_SESSION['last_action'] = time(); ``` ### Sessions Are Temporary It is important to not treat a session as permanent storage. They get cleared from time to time by the developer, whenever the application is moved to a new host server, by the application itself (for example a logout button), and even during server maintenance. For long term storage of data make sure to use a database. ### Security Last but not least it's important to use php sessions securely. Read our article on [Session Identifier Acquirement](/php/security/session-identifier-acquirement) and [Session Hijacking](/php/security/session-hijacking) for more information. #### More Information: * php.net session manual