Stec Records Forum

Tools to make music

News: Note that we've improved the security of the forum by enhancing the sign up form.

PHP Sessions (Read 2569 times)

  • Administrator
  • Hero Member
  • Chief Administrator
  • Posts: 771
  • Karma: +0/-0
  • Time reveals truth.
    • Bob Sellon's Home Page
#3 Re: PHP Sessions
June 16, 2010, 01:23:20 PM
It looks like the session id is saved in the client computer cookies. See the default for session.use_cookies in Session Runtime Configuration

  • Administrator
  • Hero Member
  • Chief Administrator
  • Posts: 771
  • Karma: +0/-0
  • Time reveals truth.
    • Bob Sellon's Home Page

  • Newbie
  • Posts: 4
  • Karma: +0/-0
#1 PHP Sessions
June 15, 2010, 04:59:13 PM
   Sessions are a convenient way of storing data throughout multiple different PHP scripts.  They are similar in purpose to cookies, as they are read in to each individual script as a global superconstant array.  Sessions are generally tracked on the server, thus are more secure than cookies (which are saved in named text files on the client machine).


   This simple function call will cause PHP to read all of the session variables into the global superconstant array $_SESSION.

<?php

session_start();

?>

   Each page that has access to the session variables must call session_start before these variables become available.  It is important to note that each call to session_start will refresh the default timeout period for each session.


   To change the timeout period of a session, use the following syntax:
<?php

// Set the timeout period to 30 seconds
ini_set('session.gc_maxlifetime',30);
session_start();

?>

   This should always happen before the session is started.


   Once a session has been started, variables may be added to the session array using the following syntax:

<?php

// Example 1
session_start();

$_SESSION["foo"] = "bar";

?>


   On another page, these variables may be accessed using the following:

<?php

// Example 2
session_start();

echo( $_SESSION["foo"] );
// Would output the string "bar", assuming example 1 was executed prior to this script.

?>