Location: PHPKode > scripts > Session Handler classes > session-handler-classes/TestSession.php3
<?
require($DOCUMENT_ROOT."/library/headers/hUtility.inc");
require($DOCUMENT_ROOT."/library/headers/hSession.inc");

class helper {
    var $a;
    var $b;
    var $c;

    function helper() {
        $this->a = 1;
        $this->b = 2;
        $this->c = 3;
    }

    function getA() {
        return $this->a;
    }

    function getB() {
        return $this->b;
    }

    function getC() {
        return $this->c;
    }

    function callback($obj) {
        $this->a = $obj->a;
        $this->b = $obj->b;
        $this->c = $obj->c;
    }
}

class Foo {
    var $a;
    var $b;
    var $c;
    var $obj;

    function Foo() {
        $this->a = 0;
        $this->b = "B";
        $this->c = "C";
        $this->obj = new helper();
    }

    function switchVars() {
        $this->a = "B";
        $this->b = "C";
        $this->c = 0;
    }

    function callback($obj) {
        $this->a = $obj->a;
        $this->b = $obj->b;
        $this->c = $obj->c;
        $this->obj->callback($obj->obj);
    }
}
?>
<html>
<head>
<title>Test script for Session object</title>
</head>
<body>
<center>
<font face="Arial" size="+2">Test Application for Session handler</font><br>
<table border=1>
  <tr>
    <td align="center" colspan=2 bgcolor="#COCOCO">
      <font face="Arial" size="+2">Diagnostics</font>
    </td>
  </tr>
  <tr>
    <td align="right">
      Session Path:
    </td>
    <td align="left">
      <? echo $SESSION->_sessionPath; ?>
    </td>
  </tr>
  <tr>
    <td align="right">
      Session ID:
    </td>
    <td align="left">
      <? echo $SESSION->_sessionId; ?>
    </td>
  </tr>
  <tr>
    <td align="right">
      Session ID Key:
    </td>
    <td align="left">
      <? echo $SESSION->_sessionIdKey; ?>
    </td>
  </tr>
  <tr>
    <td align="right">
      Timeout Key:
    </td>
    <td align="left">
      <? echo BuildPath($SESSION->_sessionPath, $SESSION->_timeoutKey); ?>
    </td>
  </tr>
  <tr>
    <td align="right">
      Current Time:
    </td>
    <td align="left">
      <? echo date("h:i A 1 F dS, Y", time()); ?>
    </td>
  </tr>
  <tr>
    <td align="right">
      Timeout Time:
    </td>
    <td align="left">
      <? echo date("h:i A 1 F dS, Y", filemtime(BuildPath($SESSION->_sessionPath, $SESSION->_timeoutKey)) + ($SESSION->_timeout * MINUTE)); ?>
    </td>
  </tr>

  <tr>
    <td align="center" colspan=2 bgcolor="#COCOCO">
      <font face="Arial" size="+2">String Test</font>
    </td>
  </tr>
  <? 
  $myval = "Hello";
  ?>
  <tr>
    <td align="right">
      $myval before register:
    </td>
    <td align="left">
      <? echo $myval; ?>
    </td>
  </tr>
  <?
  $SESSION->register("FirstKey", $myval);
  unset($myval);
  ?>
  <tr>
    <td align="right">
      $myval after unset:
    </td>
    <td align="left">
      <? if (!empty($bar)) { ?>
        <? echo $myval; ?>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $SESSION->retrieve("FirstKey", $myval);
  ?>
  <tr>
    <td align="right">
      $myval after retrieve:
    </td>
    <td align="left">
      <? echo $myval; ?>
    </td>
  </tr>
  <tr>
    <td align="center" colspan=2 bgcolor="#COCOCO">
      <font face="Arial" size="+2">Integer Test</font>
    </td>
  </tr>
  <? 
  $myval2 = 1;
  ?>
  <tr>
    <td align="right">
      $myval2 before register:
    </td>
    <td align="left">
      <? echo $myval2; ?>
    </td>
  </tr>
  <?
  $SESSION->register("SecondKey", $myval2);
  unset($myval2);
  ?>
  <tr>
    <td align="right">
      $myval2 after unset:
    </td>
    <td align="left">
      <? if (!empty($myval2)) { ?>
        <? echo $myval2; ?>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $SESSION->retrieve("SecondKey", $myval2);
  $SESSION->deleteKey("SecondKey");
  ?>
  <tr>
    <td align="right">
      $myval2 after retrieve:
    </td>
    <td align="left">
      <? echo $myval2; ?>
    </td>
  </tr>
  <tr>
    <td align="center" colspan=2 bgcolor="#C0C0C0">
      <font face="Arial" size="+2">Float Test</font>
    </td>
  </tr>
  <? 
  $myval3 = 1.213;
  ?>
  <tr>
    <td align="right">
      $myval3 before register:
    </td>
    <td align="left">
      <? echo $myval3; ?>
    </td>
  </tr>
  <?
  $SESSION->register("SecondKey", $myval3);
  unset($myval3);
  ?>
  <tr>
    <td align="right">
      $myval3 after unset:
    </td>
    <td align="left">
      <? if (!empty($myval3)) { ?>
        <? echo $myval3; ?>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $SESSION->retrieve("SecondKey", $myval3);
  $SESSION->deleteKey("SecondKey");
  ?>
  <tr>
    <td align="right">
      $myval3 after retrieve:
    </td>
    <td align="left">
      <? echo $myval3; ?>
    </td>
  </tr>
  <tr>
    <td align="center" colspan=2 bgcolor="#COCOCO">
      <font face="Arial" size="+2">Object Test</font>
    </td>
  </tr>
  <? 
  $bar = new Foo();
  ?>
  <tr>
    <td align="right">
      $bar before register:
    </td>
    <td align="left">
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
    </td>
  </tr>
  <?
  $SESSION->register("ThirdKey", $bar);
  unset($bar);
  ?>
  <tr>
    <td align="right">
      $bar after unset:
    </td>
    <td align="left">
      <? if (!empty($bar)) { ?>
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $bar = new Foo();
  $SESSION->retrieve("ThirdKey", $bar, "callback");
  $SESSION->deleteKey("ThirdKey");
  ?>
  <tr>
    <td align="right">
      $bar after retrieve:
    </td>
    <td align="left">
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
    </td>
  </tr>
  <tr>
    <td align="right">
      $bar after switch:
    </td>
    <td align="left">
      <? $bar->switchVars(); ?>
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
    </td>
  </tr>
  <?
  $SESSION->register("ThirdKey", $bar);
  unset($bar);
  ?>
  <tr>
    <td align="right">
      $bar after unset:
    </td>
    <td align="left">
      <? if (!empty($bar)) { ?>
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $bar = new Foo();
  $SESSION->retrieve("ThirdKey", $bar, "callback");
  ?>
  <tr>
    <td align="right">
      $bar after retrieve:
    </td>
    <td align="left">
      $bar-&gt;a = <? echo $bar->a; ?><br>
      $bar-&gt;b = <? echo $bar->b; ?><br>
      $bar-&gt;c = <? echo $bar->c; ?><br>
      $bar-&gt;obj-&gt;a = <? echo $bar->obj->getA(); ?><br>
      $bar-&gt;obj-&gt;b = <? echo $bar->obj->getB(); ?><br>
      $bar-&gt;obj-&gt;c = <? echo $bar->obj->getC(); ?><br>
    </td>
  </tr>
  <tr>
    <td align="center" colspan=2 bgcolor="#COCOCO">
      <font face="Arial" size="+2">Complex Array Test</font>
    </td>
  </tr>
  <? 
  $myarr = array("1", "2", "3");
  $myarr2 = array("Hello", 1, "World", $myarr);
  ?>
  <tr>
    <td align="right">
      $myarr2 before register:
    </td>
    <td align="left">
      $myarr2[0] = <? echo $myarr2[0]; ?><br>
      $myarr2[1] = <? echo $myarr2[1]; ?><br>
      $myarr2[2] = <? echo $myarr2[2]; ?><br>
      $myarr2[3][0] = <? echo $myarr2[3][0]; ?><br>
      $myarr2[3][1] = <? echo $myarr2[3][1]; ?><br>
      $myarr2[3][2] = <? echo $myarr2[3][2]; ?><br>
    </td>
  </tr>
  <?
  $SESSION->register("FourthKey", $myarr2);
  unset($myarr2);
  ?>
  <tr>
    <td align="right">
      $myarr2 after unset:
    </td>
    <td align="left">
      <? if (!empty($myarr2)) { ?>
      $myarr2[0] = <? echo $myarr2[0]; ?><br>
      $myarr2[1] = <? echo $myarr2[1]; ?><br>
      $myarr2[2] = <? echo $myarr2[2]; ?><br>
      $myarr2[3][0] = <? echo $myarr2[3][0]; ?><br>
      $myarr2[3][1] = <? echo $myarr2[3][1]; ?><br>
      $myarr2[3][2] = <? echo $myarr2[3][2]; ?><br>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
  <?
  $SESSION->retrieve("FourthKey", $myarr2);
  ?>
  <tr>
    <td align="right">
      $myarr2 after retrieve:
    </td>
    <td align="left">
      <? if (!empty($myarr2)) { ?>
      $myarr2[0] = <? echo $myarr2[0]; ?><br>
      $myarr2[1] = <? echo $myarr2[1]; ?><br>
      $myarr2[2] = <? echo $myarr2[2]; ?><br>
      $myarr2[3][0] = <? echo $myarr2[3][0]; ?><br>
      $myarr2[3][1] = <? echo $myarr2[3][1]; ?><br>
      $myarr2[3][2] = <? echo $myarr2[3][2]; ?><br>
      <? } else { ?>
      Nothing
      <? } ?>
    </td>
  </tr>
</table>
</center>
</body>
</html>
Return current item: Session Handler classes