Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Logan Dugenoux  >  Cookie session  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of use of the class
Class: Cookie session
Store session variables in a cookie when user away
Author: By
Last change: Wrong file inserted, replaced with real example.php file, with real example. sorry !
Date: 2003-11-02 12:53
Size: 1,206 bytes
 

Contents

Class file image Download
<?

require( "cookieSession.php" );
$cs = new cookieSession();
session_start() ;

//--- Reload cart if necessary
if (!isset($HTTP_SESSION_VARS["cart"]))
{    
    
$cs->readSessionCookie("cart");
    if (!isset(
$HTTP_SESSION_VARS["cart"]))
    {    
// no cookie
        
$HTTP_SESSION_VARS["cart"] = array();
    }
}

//--- Add item
if ($HTTP_POST_VARS["add"]==1)
{
    
$nbItems sizeof($HTTP_SESSION_VARS["cart"])+1;
    
$HTTP_SESSION_VARS["cart"][$nbItems] = array($HTTP_POST_VARS["lib"], $HTTP_POST_VARS["qty"] );
    
$cs->storeSessionCookie("cart");
}

//--- Del items
else if ($HTTP_POST_VARS["del"]==1)
{
    
$HTTP_SESSION_VARS["cart"] = array();
    
$cs->storeSessionCookie("cart");
}

//--- Cart display
echo "<u>Your cart :</u><br><br>";
foreach(
$HTTP_SESSION_VARS["cart"] as $i => $v)
{
    echo 
"item ".$i." : ".$v[0]." x ".$v[1]."<br>";
}

//--- Form display
echo "<br>";
echo 
"<form method=post>New item name <input name=lib size=10> x quantity <input name=qty size=10><br>";
echo 
"<input name=add type=hidden value=1><input name=sub type=submit value=add></form><br>";
echo 
"<form method=post><input name=del type=hidden value=1><input name=sub type=submit value='delete all'></form>";


?>