| px | top | add code | search | signup | login | help |
<?php
/*************************************************************************
Example given
**************************************************************************
Required:track_vars for the HTTP_POST_VARS array.
Example of usage: This will display num each time you press
the submit button the "num" var will be incremented by one.
<form method="POST" action="this.html">
<?
sess = new FormSession("Test session");
echo num;
num = sess->Get("num");
num++;
sess->Set("num", num);
sess->EndSession();
?>
<input type="submit">
</form>
**************************************************************************
Class form session
**************************************************************************/
class FormSession {
var $m_data;
var $m_name;
function FormSession($name) {
global $HTTP_POST_VARS;
$this->m_name = $name;
if (empty($HTTP_POST_VARS["$name"]))
$this->m_data = array();
else
$this->m_data =
unserialize(urldecode($HTTP_POST_VARS["$name"]));
}
function P($name) {
echo $this->m_data[$name];
}
function Get($name) {
return $this->m_data[$name];
}
function Set($name, $value) {
$this->m_data[$name] = $value;
}
function EndSession() {
$stream = urlencode(serialize($this->m_data));
echo "<input type='hidden' name='$this->m_name' value='$stream'>";
}
}
/*************************************************************************/
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.