<?php
//
// +----------------------------------------------------------------------+
// | Sitellite - Content Management System |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 Simian Systems |
// +----------------------------------------------------------------------+
// | This software is released under the Simian Open Software License. |
// | Please see the accompanying file OPENLICENSE for licensing details! |
// | |
// | You should have received a copy of the Simian Open Software License |
// | along with this program; if not, write to Simian Systems, |
// | 101-314 Broadway, Winnipeg, MB, R3C 0S7, CANADA. The Simian |
// | Public License is also available at the following web site |
// | address: <http://www.simian.ca/license.php> |
// +----------------------------------------------------------------------+
// | Authors: John Luxford <lux@simian.ca> |
// +----------------------------------------------------------------------+
//
// 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.
//
/*!
<package name="Cookie">
<class name="Cookie"
access="public"
date="2001-05-29 11:05:37"
version="1.0">
<author name="John Luxford"
email="lux@simian.ca"
url="http://www.simian.ca/" />
<summary>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.</summary>
<example>$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);
}</example> !*/
class Cookie {
/*! <property name="param" access="public" type="array">
<summary>Contains a list of the names of all the cookie variables
available to the current script.</summary>
</property> !*/
var $param = array ();
/*! <method name="Cookie" access="public">
<summary>Constructor method.</summary>
</method> !*/
function Cookie () {
global $HTTP_COOKIE, $HTTP_COOKIE_VARS;
if (strlen ($HTTP_COOKIE) > 0) {
while (list ($k, $v) = each ($HTTP_COOKIE_VARS)) {
$this->{$k} = $v;
array_push ($this->param, $k);
}
}
}
/*! <method name="set" access="public">
<summary>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.</summary>
<param name="name" type="string" />
<param name="value" type="string" />
<param name="expire" type="integer" />
<param name="path" type="string" />
<param name="domain" type="string" />
<param name="secure" type="boolean" />
</method> !*/
function set ($name = "", $value = "", $expire = "", $path = "", $domain = "", $secure = 0) {
/* if (ereg ("MSIE", getenv("HTTP_USER_AGENT"))) { #ie doesn't handle cookies properly...
if (! empty ($path)) { $path = "; path=" . $path; }
if (! empty ($domain)) { $domain = "; domain=" . $domain; }
if ($secure > 0) { $secure = "; secure"; } else { $secure = ""; }
if (! empty ($expire)) { $expire = "; expires=" . date ("l, d-M-y H:i:s", time () + $expire) . " GMT"; }
header ("set-cookie: $name=$value$domain$expire$path$secure");
} else { */
if (! empty ($expire)) {
$expire = time () + expire;
}
setcookie ($name, $value, $expire, $path, $domain, $secure);
// }
}
}
/*! </class>
</package> !*/
?>
|