Class SimpleUserAgent

Description

Fetches web pages whilst keeping track of cookies and authentication.

Located in /user_agent.php (line 31)


	
			
Method Summary
 SimpleUserAgent __construct ()
 void addAdditionalHeaders ( &$request, SimpleHttpRequest $request)
 void addHeader (string $header)
 void ageCookies (integer $interval)
 SimpleHttpRequest createHttpRequest (SimpleUrl $url,  $encoding, SimpleFormEncoding $parameters)
 SimpleHttpRequest createRequest (SimpleUrl $url, SimpleFormEncoding $encoding)
 SimpleHttpResponse fetch (SimpleUrl $url, SimpleFormEncoding $encoding)
 SimpleHttpResponse fetchResponse (string/SimpleUrl $url, SimpleEncoding $encoding)
 SimpleHttpResponse fetchWhileRedirected (SimpleUrl $url, SimpelFormEncoding $encoding)
 string/boolean getBaseCookieValue (string $name, SimpleUrl $base)
 string getCookieValue (string $host, string $path, string $name)
 void ignoreCookies ()
 boolean isTooManyRedirects (integer $redirects)
 void restart ([string/integer $date = false])
 void setConnectionTimeout (integer $timeout)
 void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
 void setIdentity (string $host, string $realm, string $username, string $password)
 void setMaximumRedirects (integer $max)
 void useCookies ()
 void useProxy (string $proxy, string $username, string $password)
Methods
Constructor __construct (line 46)

Starts with no cookies, realms or proxies.

  • access: public
SimpleUserAgent __construct ()
addAdditionalHeaders (line 322)

Adds additional manual headers.

  • access: protected
void addAdditionalHeaders ( &$request, SimpleHttpRequest $request)
addHeader (line 71)

Adds a header to every fetch.

  • access: public
void addHeader (string $header)
  • string $header: Header line to add to every request until cleared.
ageCookies (line 80)

Ages the cookies by the specified time.

  • access: public
void ageCookies (integer $interval)
  • integer $interval: Amount in seconds.
createHttpRequest (line 296)

Builds the appropriate HTTP request object.

  • return: New request object.
  • access: protected
SimpleHttpRequest createHttpRequest (SimpleUrl $url,  $encoding, SimpleFormEncoding $parameters)
  • SimpleUrl $url: Target to fetch as url object.
  • SimpleFormEncoding $parameters: POST/GET parameters.
  • $encoding
createRequest (line 279)

Creates a full page request.

  • return: New request.
  • access: protected
SimpleHttpRequest createRequest (SimpleUrl $url, SimpleFormEncoding $encoding)
  • SimpleUrl $url: Target to fetch as url object.
  • SimpleFormEncoding $encoding: POST/GET parameters.
createRoute (line 306)

Sets up either a direct route or via a proxy.

  • return: Route to take to fetch URL.
  • access: protected
SimpleRoute createRoute (SimpleUrl $url)
  • SimpleUrl $url: Target to fetch as url object.
fetch (line 267)

Actually make the web request.

  • return: Headers and hopefully content.
  • access: protected
SimpleHttpResponse fetch (SimpleUrl $url, SimpleFormEncoding $encoding)
  • SimpleUrl $url: Target to fetch.
  • SimpleFormEncoding $encoding: Additional parameters for request.
fetchResponse (line 214)

Fetches a URL as a response object. Will keep trying if redirected.

It will also collect authentication realm information.

  • return: Hopefully the target page.
  • access: public
SimpleHttpResponse fetchResponse (string/SimpleUrl $url, SimpleEncoding $encoding)
  • string/SimpleUrl $url: Target to fetch.
  • SimpleEncoding $encoding: Additional parameters for request.
fetchWhileRedirected (line 239)

Fetches the page until no longer redirected or until the redirect limit runs out.

  • return: Hopefully the target page.
  • access: protected
SimpleHttpResponse fetchWhileRedirected (SimpleUrl $url, SimpelFormEncoding $encoding)
  • SimpleUrl $url: Target to fetch.
  • SimpelFormEncoding $encoding: Additional parameters for request.
getBaseCookieValue (line 120)

Reads the current cookies within the base URL.

  • return: Null if there is no base URL, false if the cookie is not set.
  • access: public
string/boolean getBaseCookieValue (string $name, SimpleUrl $base)
  • string $name: Key of cookie to find.
  • SimpleUrl $base: Base URL to search from.
getCookieValue (line 108)

Reads the most specific cookie value from the browser cookies.

  • return: False if not present, else the value as a string.
  • access: public
string getCookieValue (string $host, string $path, string $name)
  • string $host: Host to search.
  • string $path: Applicable path.
  • string $name: Name of cookie to read.
ignoreCookies (line 131)

Switches off cookie sending and recieving.

  • access: public
void ignoreCookies ()
isTooManyRedirects (line 190)

Test to see if the redirect limit is passed.

  • return: True if over.
  • access: protected
boolean isTooManyRedirects (integer $redirects)
  • integer $redirects: Count so far.
restart (line 60)

Removes expired and temporary cookies as if the browser was closed and re-opened. Authorisation has to be obtained again as well.

  • access: public
void restart ([string/integer $date = false])
  • string/integer $date: Time when session restarted. If omitted then all persistent cookies are kept.
setConnectionTimeout (line 148)

Sets the socket timeout for opening a connection.

  • access: public
void setConnectionTimeout (integer $timeout)
  • integer $timeout: Maximum time in seconds.
setCookie (line 94)

Sets an additional cookie. If a cookie has the same name and path it is replaced.

  • access: public
void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
  • string $name: Cookie key.
  • string $value: Value of cookie.
  • string $host: Host upon which the cookie is valid.
  • string $path: Cookie path if not host wide.
  • string $expiry: Expiry date.
setIdentity (line 202)

Sets the identity for the current realm.

  • access: public
void setIdentity (string $host, string $realm, string $username, string $password)
  • string $host: Host to which realm applies.
  • string $realm: Full name of realm.
  • string $username: Username for realm.
  • string $password: Password for realm.
setMaximumRedirects (line 158)

Sets the maximum number of redirects before a page will be loaded anyway.

  • access: public
void setMaximumRedirects (integer $max)
  • integer $max: Most hops allowed.
useCookies (line 139)

Switches back on the cookie sending and recieving.

  • access: public
void useCookies ()
useProxy (line 171)

Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.

  • access: public
void useProxy (string $proxy, string $username, string $password)
  • string $proxy: Proxy URL.
  • string $username: Proxy username for authentication.
  • string $password: Proxy password for authentication.

Documentation generated on Sun, 31 Oct 2010 16:32:56 -0500 by phpDocumentor 1.4.3