Class: Cookie

  • Package: saf.CGI
  • Author: John Luxford <lux@simian.ca>
  • Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
  • License: http://www.sitellite.org/index/license Simian Open Software License
  • Version: 2.2, 2002-11-01, $Id: Cookie.php,v 1.3 2007/10/06 00:06:30 lux Exp $
  • Access: public

Cookie is a class that is used to give auto-generated Cookie
variables their own distinct namespace, so as not to conflict with
other auto-generated variables, such as CGI data. The Cookie class gets
its data from the $HTTP_COOKIE_VARS hash.

New in 1.2:
- Added support for the PHP $_COOKIE, etc. variables, via an if statement
so as to be backward-compatible with the deprecated $HTTP_*_VARS variables.

New in 1.4:
- Added the prependDot() method.

New in 1.6:
- Now relies on the $_COOKIE superglobal only, but calls "global $_COOKIE;"
so that in versions of PHP below 4.1.0, you can create a reference to
the old $HTTP_*_VARS using the new $_* names.

New in 1.8:
- Fixed a bug with the automatic stripslashes() and fields that are arrays.

New in 2.0:
- Removed a preg_match() call and replaced it with a substr_count call,
which is faster AND more effective, in the prependDot() method.

New in 2.2:
- Fixed a syntax error that was causing problems with cookies with positive
expiry times.


Usage Example


<?php

$cookie 
= new Cookie;

if (! empty (
$cookie->session_id)) {
    
// do something with the cookie
} else {
    
// set the cookie
    
$cookie->set ("session_id""value"1800"/"".site.com"0);
}

?>

Return to Top



Properties


$param = array ()

  • Access: public

Contains a list of the names of all the cookie variables
available to the current script.


$files = array ()

  • Access: public

Contains a list of the names of all the file upload variables
passed to the current script through the POST method.


$error

  • Access: public

Contains an error message describing the reason for a verify ()
failure.

Return to Top



Methods


Cookie ()

  • Access: public

Constructor method.


prependDot ($domain)

  • Access: public
  • Return: string

Returns the domain passed to it, with a prepended dot (.) if
the domain contains only a single dot (since the cookie specs say that
two dots are required). This is a workaround that lets us pass our
Session object a $site with a domain like 'yoursite.com', and have it
automatically know to set the cookie for '.yoursite.com'.


set ($name = '', $value = '', $expire = '', $path = '', $domain = '', $secure = 0)

  • Access: public
  • Return: boolean

Sends a 'set-cookie' HTTP header to the browser. Must be called
before any data has been sent.

$expire is the number of seconds from the current time.
$domain must contain at least two periods (.).
$secure accepts a 1 or a 0 to denote true or false.

Return to Top

Copyright © 2008 Sitellite CMS Project

Powered by Sitellite 5.0 Content Management System