Class cms_http_request

Description

HTTP Class

This is a wrapper HTTP class that uses either cURL or fsockopen to harvest resources from web. This can be used with scripts that need a way to communicate with various APIs who support REST.

  • author: Md Emran Hasan <phpfour@gmail.com>
  • copyright: 2007-2008 Md Emran Hasan
  • link: http://www.phpfour.com/lib/http
  • since:

    Version 0.1

    Modified by Robert Campbell (calguy1000@cmsmadesimple.org) Renamed the class to cms_http_request Fixed some bugs.

Located in /class.cms_http_request.php (line 25)


	
			
Method Summary
static void is_curl_suitable ()
void __construct ()
void addCookie (string $name, string $value)
void addParam (string $name, string $value)
void addRequestHeader ( $str, [ $prepend = false])
void clear ()
string execute ([string $target = ''], [string $referrer = ''], [string $method = ''], [array $data = array()])
void followRedirects ([boolean $value = TRUE])
string getError ()
array getHeaders ()
string getResult ()
integer getStatus ()
void initialize ([array $config = array()])
void requestHeaderExists ( $key)
void resetCookies ()
void saveCookie ([boolean $value = TRUE])
void setAuth (string $username, string $password)
void setCookiepath (string $path)
void setMaxredirect (integer $value)
void setMethod (string $method)
void setParams (array $dataArray)
void setRawPostData ( $data)
void setReferrer (string $referrer)
void setTarget (string $url)
void setTimeout (integer $seconds)
void setUseragent (string $agent)
void useCookie ([boolean $value = TRUE])
void useCurl ([boolean $value = TRUE])
Methods
static method is_curl_suitable (line 695)
  • access: public
static void is_curl_suitable ()
Constructor __construct (line 256)

Constructor for initializing the class with default values.

  • access: public
void __construct ()
addCookie (line 525)

Add a cookie to the request

void addCookie (string $name, string $value)
  • string $name: Name of cookie
  • string $value: Value of cookie
addParam (line 510)

Add request parameters

void addParam (string $name, string $value)
  • string $name: Name of the parameter
  • string $value: Value of the parameter
addRequestHeader (line 656)

Add a request header

void addRequestHeader ( $str, [ $prepend = false])
  • $str
  • $prepend
clear (line 314)

Clear Everything

Clears all the properties of the class and sets the object to the beginning state. Very handy if you are doing subsequent calls with different data.

void clear ()
execute (line 734)

Execute a HTTP request

Executes the http fetch using all the set properties. Intellegently switch to fsockopen if cURL is not present. And be smart to follow redirects (if asked so).

  • return: Response body of the target page
  • access: public
string execute ([string $target = ''], [string $referrer = ''], [string $method = ''], [array $data = array()])
  • string $target: URL of the target page (optional)
  • string $referrer: URL of the referrer page (optional)
  • string $method: The http method (GET or POST) (optional)
  • array $data: Parameter array for GET or POST (optional)
followRedirects (line 581)

Whether to follow HTTP redirects

void followRedirects ([boolean $value = TRUE])
  • boolean $value: Whether to follow HTTP redirects or not
getError (line 624)

Get last execution error

  • return: last error message (if any)
string getError ()
getHeaders (line 604)

Get execution result headers

  • return: last headers of execution
array getHeaders ()
getResult (line 594)

Get execution result body

  • return: output of execution
string getResult ()
getStatus (line 614)

Get execution status code

  • return: last http status code
integer getStatus ()
initialize (line 284)

Initialize preferences

This function will take an associative array of config values and will initialize the class variables using them.

Example use:

 $httpConfig['method']     = 'GET';
 $httpConfig['target']     = 'http://www.somedomain.com/index.html';
 $httpConfig['referrer']   = 'http://www.somedomain.com';
 $httpConfig['user_agent'] = 'My Crawler';
 $httpConfig['timeout']    = '30';
 $httpConfig['params']     = array('var1' => 'testvalue', 'var2' => 'somevalue');

 $http = new Http();
 $http->initialize($httpConfig);

void initialize ([array $config = array()])
  • array $config: Config values as associative array
requestHeaderExists (line 632)

Request Header Exists?

void requestHeaderExists ( $key)
  • $key
resetCookies (line 359)

Clear all cookies

  • author: Robert Campbell (calguy1000@gmail.com)
void resetCookies ()
saveCookie (line 567)

Whether to save persistent cookies in subsequent calls

void saveCookie ([boolean $value = TRUE])
  • boolean $value: Whether to save persistent cookies or not
setAuth (line 480)

Set basic http authentication realm

void setAuth (string $username, string $password)
  • string $username: Username for authentication
  • string $password: Password for authentication
setCookiepath (line 441)

Set cookie path (cURL only)

void setCookiepath (string $path)
  • string $path: File location of cookiejar
setMaxredirect (line 495)

Set maximum number of redirection to follow

void setMaxredirect (integer $value)
  • integer $value: Maximum number of redirects
setMethod (line 384)

Set http method

void setMethod (string $method)
  • string $method: HTTP method to use (GET or POST)
setParams (line 461)

Set request parameters

void setParams (array $dataArray)
  • array $dataArray: All the parameters for GET or POST
setRawPostData (line 449)
void setRawPostData ( $data)
  • $data
setReferrer (line 399)

Set referrer URL

void setReferrer (string $referrer)
  • string $referrer: URL of referrer page
setTarget (line 370)

Set target URL

void setTarget (string $url)
  • string $url: URL of target resource
setTimeout (line 427)

Set timeout of execution

void setTimeout (integer $seconds)
  • integer $seconds: Timeout delay in seconds
setUseragent (line 413)

Set User agent string

void setUseragent (string $agent)
  • string $agent: Full user agent string
useCookie (line 553)

Whether to use cookies or not

void useCookie ([boolean $value = TRUE])
  • boolean $value: Whether to use cookies or not
useCurl (line 539)

Whether to use cURL or not

void useCurl ([boolean $value = TRUE])
  • boolean $value: Whether to use cURL or not

Documentation generated on Sun, 12 Aug 2012 08:38:27 -0600 by phpDocumentor 1.3.2