·  PHP – Terms – Session – Summery

 

- Info:

  - This tutorial contains summery of session related functionality.

 

- Example:

  - Create PHP Console Application Test.php.

 

    Test.html

    <?php

   

      //CONTROL SESSION.

      session_start();                               //Start automatic session handling.

      session_destroy();                             //Destroy session.

      session_unset();                               //Delete all session variables.

     

      //CONTROL SID.

      $SID = session_id();                           //Get session ID.

      $SID = session_id("Custom1234");               //Set session ID.

     

      //STORE AND RETREIVE SCALAR FROM SESSION.

      $_SESSION['username'] = "jason";               //Store string into session.

      $username             = $_SESSION['username']; //Get string from session.

      

      //STORE AND RETREIVE OBJECT FROM SESSION.

      $myObject               = new MyClass();

      $_SESSION['serialized'] = serialize($myObject);

      $unserialized           = unserialize($_SESSION['serialized']);

   

      //DELETE SESSION VARIABLE.

      unset($_SESSION['username']);                  //Delete session variable. 

      

    ?>