File: index.php

Recommend this page to a friend!
  Classes of Justin Koivisto  >  phpMysqlSessions  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: First of 3 test pages
Class: phpMysqlSessions
Author: By
Last change:
Date: 20 years ago
Size: 1,966 bytes
 

 

Contents

Class file image Download
<?
   
// Need the class definition
   
require "_class.session.php";

   
// Instantiate a session
   
$my_session=new session_class("znet_shop");

   
// Remove old session from db (300 sec.)
   
$my_session->RemoveExpired(300);

   
// Start session or get previous data
   
$my_session->Initiate();

   
/* For this example, I will use normal variables as
        well as an array of values to show how to use arrays
        of data for the sessions (may be used in something like
        a shopping cart application.
    */

    // First, we will assign the variables some values
   
$var1="var1";
   
$var2=2;
   
$var3=$var1 ." != " .$var2; // "var1 != 2"

    // Now let's make an array
   
for($i=0;$i<5;$i++)
       
$array1[$i]="element ".$i;

   
// Let's make another
   
$array2=array("first"=>1, "second"=>2, "third"=>3, "fourth"=>4);

   
// Now we will register the variables into the session data if they aren't
    // already registered
   
if(!$my_session->IsRegistered("var1"))
       
$my_session->Register("var1");
    if(!
$my_session->IsRegistered("var2"))
       
$my_session->Register("var2");
    if(!
$my_session->IsRegistered("var3"))
       
$my_session->Register("var3");

   
// Now of the arrays
   
$arr1=serialize($array1);
    if(!
$my_session->IsRegistered("arr1"))
       
$my_session->Register("arr1");
   
$arr2=serialize($array2);
    if(!
$my_session->IsRegistered("arr2"))
       
$my_session->Register("arr2");

   
// Now that all the data is registered as session data, let's save it.
   
$my_session->Save();
   
$my_sid=$my_session->GetID();
?>
<html><body>
<h1>Session Test</h1>
The following values should be saved in your session database:<br>
Session ID: <? echo $my_sid ?><br>
<table border=3>
 <tr><td>$var1</td><td><? echo $var1 ?></td></tr>
 <tr><td>$var2</td><td><? echo $var2 ?></td></tr>
 <tr><td>$var3</td><td><? echo $var3 ?></td></tr>
 <tr><td>$arr1</td><td><? echo $arr1 ?></td></tr>
 <tr><td>$arr2</td><td><? echo $arr2 ?></td></tr>
</table>

<a href="next.php">Next</a>
</body></html>


For more information send a message to info at phpclasses dot org.