PHP WebSocket2 Library
PHP5 Library for browsing web
HttpCookie Class Reference

HTTP cookie. More...

Public Member Functions

 __construct ($name, $value= '')
 Constructor. More...
 
 __toString ()
 Converts cookie to string, which is suitable for HTTP request. More...
 
 getName ()
 Returns cookie name. More...
 
 getValue ()
 Returns cookie value. More...
 
 getPath ()
 Returns cookie path. More...
 
 getDomain ()
 Returns cookie domain. More...
 
 isExactDomain ()
 Returns true, if cookie domain must match to server domain exactly. More...
 
 getExpires ()
 Returns cookie expiry UNIX timestamp. More...
 
 isHttpOnly ()
 Returns true, if cookie has HttpOnly attribute. More...
 
 isSecure ()
 Returns true, if cookie can be sent only over HTTPS. More...
 
 setName ($name)
 Sets cookie name. More...
 
 setValue ($value)
 Sets cookie value. More...
 
 setPath ($path)
 Sets cookie path. More...
 
 setDomain ($domain, $exact=false)
 Sets cookie domain. More...
 
 setExpires ($expires)
 Sets cookie expiry time. More...
 
 setHttpOnly ($http_only=true)
 Sets if cookie has HTTP only attribute. More...
 
 setSecure ($secure=true)
 Sets if cookie can be sent only over HTTPS. More...
 
 isExpired ($current_time)
 Returns true, if cookie is expired. More...
 
 isAccepted ($domain, $path, $secure)
 Returns true, if cookie can be sent to specified domain, path and protocol. More...
 
 toResponseString ()
 Returns cookie string that corresponds to Set-Cookie header format. More...
 

Static Public Member Functions

static parseCookieDate ($cookie_date)
 Parses cookie date string to UNIX timestamp. More...
 
static fromString ($str, WebRequest $request=null, ICookieTimeProvider $cookie_time_provider=null)
 Creates HttpCookie object from cookie header value string. More...
 

Detailed Description

HTTP cookie.

Examples:
http_cookies.php.

Constructor & Destructor Documentation

__construct (   $name,
  $value = '' 
)

Constructor.

Parameters
string$nameCookie name
mixed$valueCookie value (any scalar PHP type)

Member Function Documentation

__toString ( )

Converts cookie to string, which is suitable for HTTP request.

See also HttpCookie::toResponseString.

Return values
stringCookie string value
static fromString (   $str,
WebRequest  $request = null,
ICookieTimeProvider  $cookie_time_provider = null 
)
static

Creates HttpCookie object from cookie header value string.

Parameters
string$strValue of Set-Cookie header
WebRequest$requestOriginal WebRequest is needed to check/calculate domain and path of cookie. Can be null. If WebRequest is passed, then domain and path of cookie will be calculated if needed and checked properly.
ICookieTimeProvider$cookie_time_providerCookie time provider, can be passed to provide the time, which can be used for "expires" value calculation. Can be null.
Return values
HttpCookieCookie object or null on error
getDomain ( )

Returns cookie domain.

Return values
stringCookie domain
Examples:
http_cookies.php.
getExpires ( )

Returns cookie expiry UNIX timestamp.

Return values
stringCookie expiry UNIX timestamp
getName ( )

Returns cookie name.

Return values
stringCookie name
Examples:
http_cookies.php.
getPath ( )

Returns cookie path.

Return values
stringCookie path
Examples:
http_cookies.php.
getValue ( )

Returns cookie value.

Return values
stringCookie value
Examples:
http_cookies.php.
isAccepted (   $domain,
  $path,
  $secure 
)

Returns true, if cookie can be sent to specified domain, path and protocol.

Parameters
string$domainHost domain
string$pathRequest URI path portion
bool$secureIf true, HTTPS protocol, otherwise HTTP
Return values
stringTrue, if cookie can be sent to specified domain, path and protocol
isExactDomain ( )

Returns true, if cookie domain must match to server domain exactly.

Return values
stringTrue, if cookie domain must match to server domain exactly
isExpired (   $current_time)

Returns true, if cookie is expired.

Parameters
mixed$current_timeCan be null, which means session end. Can be int (current UNIX timestamp)
Return values
stringTrue, if cookie is expired
isHttpOnly ( )

Returns true, if cookie has HttpOnly attribute.

Return values
stringTrue, if cookie has HttpOnly attribute
isSecure ( )

Returns true, if cookie can be sent only over HTTPS.

Return values
stringTrue, if cookie can be sent only over HTTPS
static parseCookieDate (   $cookie_date)
static

Parses cookie date string to UNIX timestamp.

Parameters
string$cookie_dateCookie date string
Return values
intUNIX timestamp or null on error
setDomain (   $domain,
  $exact = false 
)

Sets cookie domain.

Parameters
string$domainCookie domain
bool$exactIf true, exact domain matching must be performed by isAccepted
setExpires (   $expires)

Sets cookie expiry time.

Parameters
int$expiresCookie expiry time (UNIX timestamp)
setHttpOnly (   $http_only = true)

Sets if cookie has HTTP only attribute.

Parameters
bool$http_onlyIf true, cookie has HTTP only attribute
setName (   $name)

Sets cookie name.

Parameters
string$nameCookie name
setPath (   $path)

Sets cookie path.

Parameters
string$pathCookie path
setSecure (   $secure = true)

Sets if cookie can be sent only over HTTPS.

Parameters
bool$secureIf true, cookie can be sent only over HTTPS
setValue (   $value)

Sets cookie value.

Parameters
mixed$valueCookie value (any PHP scalar type)
toResponseString ( )

Returns cookie string that corresponds to Set-Cookie header format.

Note that this string can differ from source string which was passed to HttpCookie::fromString. See also HttpCookie::__toString.

Return values
stringCookie string

The documentation for this class was generated from the following file: