Class PHRUTS_Cookie

Description

Cookie

A cookie has a name, a single value and optional attributes such as path, domain qualifiers and a maximum age.

This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability.

  • author: John WILDENAUER <jwilde@users.sourceforge.net> (PHP4 port of Struts)
  • author: Olivier HENRY <oliv.henry@gmail.com> (PHP5 port of Struts)
  • version: $Id: PHRUTS_Cookie.php,v 1.2 2008/05/21 16:50:27 ohenry Exp $
  • copyright: Copyright PHruts 2008

Located in /connector/PHRUTS_Cookie.php (line 36)


	
			
Variable Summary
string $domain
boolean $httpOnly
integer $maxAge
string $name
string $path
boolean $secure
string $value
Method Summary
PHRUTS_Cookie __construct (string $name, string $value)
string getDomain ()
boolean getHttpOnly ()
integer getMaxAge ()
string getName ()
string getPath ()
boolean getSecure ()
A getValue ()
boolean isToken (string $value)
void setDomain (string $pattern)
void setHttpOnly (boolean $httpOnly)
void setMaxAge (integer $expiry)
void setPath (string $uri)
void setSecure (boolean $flag)
void setValue (string $newValue)
Variables
string $domain = null (line 56)
  • access: private
boolean $httpOnly = false (line 64)
  • access: private
integer $maxAge = -1 (line 48)
  • access: private
string $name = null (line 40)
  • access: private
string $path = null (line 52)
  • access: private
boolean $secure = false (line 60)
  • access: private
string $value = null (line 44)
  • access: private
Methods
Constructor __construct (line 84)

Constructs a cookie with a specified name and value.

The name must conform to RFC 2109. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white space or begin with a $ character. The cookie's name cannot be changed after creation.

The value can be anything the server chooses to send. Its value is probably of interest only to the server. The cookie's value can be changed after creation with the setValue method.

  • throws: PHRUTS_IllegalArgumentException - If the cookie name contains illegal characters (for example, a comma, space, or semicolon) or it is one of the tokens reserved for use by the cookie protocol
  • access: public
PHRUTS_Cookie __construct (string $name, string $value)
  • string $name: A string specifying the name of the cookie
  • string $value: A string specifying the value of the cookie
getDomain (line 222)

Returns the domain name set for this cookie.

The form of the domain name is set by RFC 2109.

  • return: A string containing the domain name
  • access: public
string getDomain ()
getHttpOnly (line 270)

Return true if the cookie is accessible only through the HTTP protocol.

  • access: public
boolean getHttpOnly ()
getMaxAge (line 165)

Returns the maximum age of the cookie, specified in seconds.

By default, -1 indicating the cookie will persist until browser shutdown.

  • return: An integer specifying the maximum age of the cookie in seconds; if negative, means the cookie persists until browser shutdown
  • access: public
integer getMaxAge ()
getName (line 110)

Returns the name of the cookie.

The name cannot be changed after creation.

  • return: A string specifying the cookie's name
  • access: public
string getName ()
getPath (line 195)

Returns the path on the server to which the browser returns this cookie.

The cookie is visible to all subpaths on the server.

  • return: A string specifying a path that contains a servlet name, for example, /catalog
  • access: public
string getPath ()
getSecure (line 247)

Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.

  • return: True if the browser uses a secure protocol; otherwise, false
  • access: public
boolean getSecure ()
getValue (line 134)

Returns the value of the cookie.

  • return: string containing the cookie's present value
  • access: public
A getValue ()
isToken (line 281)

Tests a string and returns true if the string counts as a reserved token in the PHP language.

  • return: True if the string is a reserved token; false if it is not
  • access: private
boolean isToken (string $value)
  • string $value: value The string to be tested
setDomain (line 211)

Specifies the domain within which this cookie should be presented.

The form of the domain name is specified by RFC 2109. A domain name begins with a dot (".foo.com") and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example, "www.foo.com", but not "a.b.foo.com". By default, cookies are only returned to the server that sent them.

  • access: public
void setDomain (string $pattern)
  • string $pattern: A string containing the domain name within which this cookie is visible; form is according to RFC 2109
setHttpOnly (line 261)

When true the cookie will be made accessible only through the HTTP protocol.

This means that the cookie won't be accessible by scripting languages, such as JavaScript. This setting can effectly help to reduce identity theft through XSS attacks (although it is not supported by all browsers).

  • access: public
void setHttpOnly (boolean $httpOnly)
  • boolean $httpOnly
setMaxAge (line 153)

Sets the maximum age of the cookie in seconds.

A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.

A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.

  • access: public
void setMaxAge (integer $expiry)
  • integer $expiry: An integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
setPath (line 183)

Specifies a path for the cookie to which the client should return the cookie.

The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.

Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.

  • access: public
void setPath (string $uri)
  • string $uri: A string specifying a path
setSecure (line 236)

Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.

The default value is false.

  • access: public
void setSecure (boolean $flag)
  • boolean $flag: If true, sends the cookie from the browser to the server using only when using a secure protocol; if false, sent on any protocol
setValue (line 125)

Assigns a new value to a cookie after the cookie is created.

Null or empty value causes the cookie to be deleted.

If you use a binary value, you may want to use BASE64 encoding.

With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons.

  • access: public
void setValue (string $newValue)
  • string $newValue: A string specifying the new value

Documentation generated on Sat, 31 May 2008 15:46:01 +0200 by phpDocumentor 1.4.1