public static $httpsRequired = false; // Flag indicating whether the cookie should be sent over HTTPS only
public static $httponly = true; // Flag indicating that the cookie will be made accessible only
// through the HTTP protocol - and not thru JavaScript (for security)
public static $path = "/"; // The path on the server in which the cookie will be available from;
// if set to '/', the cookie will be available within the entire domain
public static function set($name, $value, $expire, $domain = false)
/* Cookie-setting function.
IMPORTART: it must be called *prior* to outputting any text
ARGUMENTS
$name String with cookie name (cannot be empty)
$value String with cookie value
$expire The time (expressed as a Unix timestamp) when the cookie is set to expire.
If set to 0, it'll expire at the end of the session (when the browser closes)
To avoid having to deal with Unix-timestamp values, more specialized methods, such as setDays(), are also provided in this class.
$domain [OPTIONAL] Site's domain name (such as "example.com"); if missing, the domain is inferred from the server variable "SERVER_NAME"
RETURN VALUE: If output exists prior to calling this function, this function will fail and return FALSE;
if it successfully runs, it will return TRUE. (This does NOT indicate whether the user accepted the cookie.)
*/
public static function setSessionOnly($name, $value, $domain = false)
// Same as set(), but the cookie will expire at the end of the session (when the browser closes)
public static function setDays($name, $value, $expireDays, $domain = false)
// Same as set(), but with the expiration time expressed as in "number of days from now"
public static function setYears($name, $value, $expireYears, $domain = false)
// Same as set(), but with the expiration time expressed as in "number of years from now"
public static function clear($name, $domain = false)
/* Clear the cookie with the given name, in the specified domain (such as "example.com")
IMPORTART: it must be called *prior* to outputting any text.
If the site's domain name (such as "example.com") is missing, it is inferred from the server variable "SERVER_NAME"
RETURN VALUE: If output exists prior to calling this function, this function will fail and return FALSE;
if it successfully runs, it will return TRUE. (This does not indicate whether the user accepted the cookie.)
*/
public static function get($name)
// Return the value of the cookie with the specified name (in the domain of the calling script); if none is found, return false
public static function isCookieSet($name)
// Return true if a cookie by that name is set (in the domain of the calling script)
public static function requireHTTPS($required = true)
// Use this function to require an HTTPS connection (or to turn off such a requirement if previously set)
public static function forceHTTPonly($force = true)
// Use this function to restrict the cookie's access thru the HTTP protocol, rather than thru JavaScript (or to turn off such a requirement if previously set)
public static function setPath($path = "/")
// Use this function to set the path on the server in which the cookie will be available from;
// if using '/', the cookie will be available within the entire domain