Login   Register  
PHP Classes

File: CookieManager.examples.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of F. Scott Gale  >  Cookie Manager  >  CookieManager.examples.php  >  Download  
File: CookieManager.examples.php
Role: Example script
Content type: text/plain
Description: A series of examples to show the use of the CookieManager and associated classes.
Class: Cookie Manager
Manage HTTP request cookies
Author: By
Last change:
Date: 3 years ago
Size: 1,842 bytes


Class file image Download
// include and instantiate a CookieManager
$cMgr = new CookieManager();

// create two simple cookies (one for prior to PHP 5.2.7 and one for the newest versions)
$cookie1 = new CookiePHP("myCookie""cookie1value");
$cookie2 = new CookiePHP5("my2ndCookie""cookie2value");

// add the cookies

// activate all the present cookies in the manager
// NOTE: by not supplying a $name value it activates all current cookies if they are not already activated

// create another cookie, let the manager determine the object type to use based on PHP version
$cMgr->create("anotherCookie""cookie3value"time() + 3600""".example.com"falsetrue);

// deactivate a specific cookie
// NOTE: by supplying a cookie's name it will deactivate only that cookie

// make sure it's deactivated
if (!$cMgr->activated("my2ndCookie"))
// NOTE: you probably wouldn't want to do this with other cookie actions being performed afterwards
echo "my2ndCookie deactivated successfully";

// make sure the cookie exists
if ($cMgr->exists("anotherCookie"))
// activate it
// verify
if ($cMgr->activated("anotherCookie"))
// NOTE: you probably wouldn't want to do this with other cookie actions being performed afterwards
echo "anotherCookie was successfully activated";

// completely remove a cookie

// get direct access to a specific cookie
$aCookie $cMgr->getCookie("anotherCookie");
// verify it's not activated
if (!$aCookie->status())
// change its value and activate it
$aCookie->Value "changedValue";
$aCookie->Secure true;