Members

Note: You can use your Sitellite.org account here and vice versa.

Username

Password

Remember Login

Forgot your password?

Not a member? Click here to register

Cookie Object

Home Page | All Pages | Recently Revised | Authors | Feeds |

The saf.CGI.Cookie package, accessible via the global $cookie object instance in Sitellite, provides a wrapper around PHP's browser cookie handling. At its most basic, the $cookie object is the OOP equivalent of the $_COOKIE array, but it also provides a set() method which wraps around the PHP setcookie() function. This method automatically sets the domain correctly if a port number is included (ie. by retrieving the $_SERVER['HTTP_HOST'] value, and allows you to simply pass it a number of seconds instead of time() + $seconds. It also properly adds the second dot (.) to a domain name even if the one you provide is missing it (ie. example.com becomes .example.com). For example:


<?php

global $cookie;

if (! empty ($cookie->name)) {
    // do something with the cookie
    echo $cookie->name;
} else {
    // set the cookie
    $cookie->set ('name', 'value', 3600, '/', 'example.com');
}

?>

The $cookie object complements the $cgi object, both of which were made long before $_COOKIE and the other superglobals.

For more information about objects in Sitellite, see the Sitellite API reference at:

http://www.sitellite.org/docs/

Created on April 14, 2005 2:46 AM by lux

Linked from: Libraries