PHP Session

You can use SESSIONS to store persistent user preferences on your Website. Each session has a data store related to it and its content persists between pages.

To start using a session you need to call session_start(), but you have to remember:

  • you can call session_start() just once per file
  • you need to call it before the script generates any output (before you send any data to the browser)

Session_start() will load session data in the $_SESSION associative array.

The easiest way to store data in a session is:

$_SESSION[‘name’] = “value”;

Here a simple example about how to use $_SESSION:

To end a session, you can use session_destroy()