PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of AMit Pandey  >  PHP Cookie Class  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: This is example how to use cookie cookie class
Class: PHP Cookie Class
Manipulate cookie values
Author: By
Last change:
Date: 8 years ago
Size: 1,999 bytes
 

Contents

Class file image Download
<?php
  
include("class.cookie.php");


##//## SET Cookie ##//## SET Cookie ##//## SET Cookie ##//## SET Cookie
    // Create a local object
   
$PHP_COOKIE=new PHP_COOKIE("test_cookie");
   
   
// Add the variables to be saved in the cookie
   
$PHP_COOKIE->put("namefirst","Jo");
   
$PHP_COOKIE->put("namelast","Foo");
   
$PHP_COOKIE->put("number","1234");
   
$PHP_COOKIE->put("time",time());
  
// Set the cookie
   
$PHP_COOKIE->set();

   
$PHP_COOKIE=new PHP_COOKIE("test_cookie 123");
   
// Add the variables to be saved in the cookie
   
$PHP_COOKIE->put("namefirst","Jo123");
   
$PHP_COOKIE->put("namelast","Foo13");
   
$PHP_COOKIE->put("number","123413");
 
// Set the cookie
   
$PHP_COOKIE->set();

    echo
"<br>The values saved in the cookie test_cookie are:";
    echo
"<br>namefirst: = $_COOKIE[namefirst]";
    echo
"<br>namelast: = $_COOKIE[namelast]";
    echo
"<br>number: = $_COOKIE[number]";
    echo
"<br>time: = $_COOKIE[time]";
    echo
"<br><br>END";
?>








<?php
  
include("class.cookie.php");
##//## GET Cookie ##//## GET Cookie ##//## GET Cookie ##//## GET Cookie
    // Extract all the variables out of the saved cookie
    // into their own 'cookies'
   
PHP_COOKIE::extract("test_cookie");

   
// Display the values found
   
echo "<BR> Values of variables retrieved from test_cookie" ;
    echo
"<br> Name: ";
    echo
$_COOKIE['namefirst'];
    echo
" ";
    echo
$_COOKIE['namelast'];
    echo
"<br> Number: ";
    echo
$_COOKIE['number'];
    echo
"<br> Time: ";
    echo
$_COOKIE['time'];
   
    echo
"<br><br>END";
?>

<?php
  
include("class.cookie.php");

##//## DELETE Cookie ##//## DELETE Cookie ##//## DELETE Cookie ##//## DELETE Cookie
  // You can destroy the entire cookie two ways.
  // 1. set the expire time in the past
  // 2. call the clear() method and then the set() method.

    // Create a local object
   
$PHP_COOKIE=new PHP_COOKIE("test_cookie", time()-86400);
 
// Set the cookie
   
$PHP_COOKIE->set();

   
 
// Clear all values
  # $PHP_COOKIE->clear();
?>