PHP Classes

File: demo_SafeCookie.php

Recommend this page to a friend!
  Classes of Ray Paseur  >  PHP Secure Cookie  >  demo_SafeCookie.php  >  Download  
File: demo_SafeCookie.php
Role: Example script
Content type: text/plain
Description: Demonstration Script
Class: PHP Secure Cookie
Store cookies allowing to detect unwanted changes
Author: By
Last change:
Date: 1 year ago
Size: 1,169 bytes
 

Contents

Class file image Download
<?php // demo/safe_cookie.php
/**
 * Demonstrate an anti-tamper cookie
 */
error_reporting(E_ALL);

require_once(
'class_SafeCookie.php');

ob_start();
echo
'<pre>';

// Set the cookie name (other values have reasonable defaults)
$name = 'My_Cookie';
$mycookie = new SafeCookie($name);

// First time the cookie will be empty
echo PHP_EOL . "Trying to get() cookie '$name'";
$value = $mycookie->get();
if (
$value) {
    echo
PHP_EOL . "The value of $name is '$value'";
} else {
    echo
PHP_EOL . "The value of $name was not returned";
}

// After setting the cookie value, subsequent HTTP requests will provide the cookie
$value = 'Hello from McLean, VA';
echo
PHP_EOL . "Trying to set('$value') on $name";
$mycookie->set($value);

// Try refreshing the browser or clicking this link to see the cookie being returned
echo PHP_EOL . '<a href="' . $_SERVER['PHP_SELF'] . '">Refresh to see the cookie status</a>';
echo
PHP_EOL;

// Try clicking this link to damage the cookie, then use the browser "back" button to see the effect
echo PHP_EOL . '<a target="remoteDetonator" href="aux_SafeCookie.php?n=' . urlencode($name) . '&v=bogus">Click here to damage the cookie</a>';


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