PHP/Cookie Session/Session Variables Create

Материал из Web эксперт
Перейти к: навигация, поиск

Create session variable

   <source lang="html4strict">

<?php

  session_start();
  $_SESSION["username"] = "Joe";
  echo "Your username is ".$_SESSION["username"].".";

?>


      </source>
   
  


Initiate session and create a few session variables

   <source lang="html4strict">

<?php

  // Initiate session and create a few session variables
  session_start();
  // Set the variables. These could be set via an HTML form, for example.
  $_SESSION["username"] = "joe";
  $_SESSION["loggedon"] = date("M d Y H:i:s");
  // Encode all session data into a single string and return the result
  $sessionVars = session_encode();
  echo $sessionVars;

?>

      </source>