FreenetIS
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
Curl_HTTP_Client Class Reference

Curl based HTTP Client Simple but effective OOP wrapper around Curl php lib. More...

Inheritance diagram for Curl_HTTP_Client:
Vtiger_HTTP_Client

Public Member Functions

 __construct ($debug=false)
 Curl_HTTP_Client constructor.
 init ()
 Init Curl session public.
 set_credentials ($username, $password)
 Set username/pass for basic http auth.
 set_referrer ($referrer_url)
 Set referrer.
 set_user_agent ($useragent)
 Set client's useragent.
 include_response_headers ($value)
 Set to receive output headers in all output functions.
 set_proxy ($proxy)
 Set proxy to use for each curl request.
 send_post_data ($url, $postdata, $ip=null, $timeout=10)
 Send post data to target URL return data returned from url or false if error occured.
 fetch_url ($url, $ip=null, $timeout=5)
 fetch data from target URL return data returned from url or false if error occured
 fetch_into_file ($url, $fp, $ip=null, $timeout=5)
 Fetch data from target URL and store it directly to file.
 send_multipart_post_data ($url, $postdata, $file_field_array=array(), $ip=null, $timeout=30)
 Send multipart post data to the target URL return data returned from url or false if error occured (contribution by vule nikolic, vule@.nosp@m.dink.nosp@m.e.net)
 store_cookies ($cookie_file)
 Set file location where cookie data will be stored and send on each new request.
 set_cookie ($cookie)
 Set custom cookie.
 get_effective_url ()
 Get last URL info usefull when original url was redirected to other location public.
 get_http_response_code ()
 Get http response code public.
 get_error_msg ()
 Return last error message and error number.
 close ()
 Close curl session and free resource Usually no need to call this function directly in case you do you have to call init() to recreate curl public.

Public Attributes

 $ch
 $debug = false
 $error_msg

Detailed Description

Curl based HTTP Client Simple but effective OOP wrapper around Curl php lib.

Contains common methods needed for getting data from url, setting referrer, credentials, sending post data, managing cookies, etc.

Samle usage: $curl = &new Curl_HTTP_Client(); $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $curl->set_user_agent($useragent); $curl->store_cookies("/tmp/cookies.txt"); $post_data = array('login' => 'pera', 'password' => 'joe'); $html_data = $curl->send_post_data(http://www.foo.com/login.php, $post_data);

Constructor & Destructor Documentation

Curl_HTTP_Client::__construct (   $debug = false)

Curl_HTTP_Client constructor.

Parameters
booleandebug public

Reimplemented in Vtiger_HTTP_Client.

Member Function Documentation

Curl_HTTP_Client::fetch_into_file (   $url,
  $fp,
  $ip = null,
  $timeout = 5 
)

Fetch data from target URL and store it directly to file.

Parameters
stringurl
resourcevalue stream resource(ie. fopen)
stringip address to bind (default null)
inttimeout in sec for complete curl operation (default 5)
Returns
boolean true on success false othervise public
Curl_HTTP_Client::fetch_url (   $url,
  $ip = null,
  $timeout = 5 
)

fetch data from target URL return data returned from url or false if error occured

Parameters
stringurl
stringip address to bind (default null)
inttimeout in sec for complete curl operation (default 5)
Returns
string data public
Curl_HTTP_Client::get_effective_url ( )

Get last URL info usefull when original url was redirected to other location public.

Returns
string url
Curl_HTTP_Client::get_error_msg ( )

Return last error message and error number.

Returns
string error msg public
Curl_HTTP_Client::get_http_response_code ( )

Get http response code public.

Returns
int
Curl_HTTP_Client::include_response_headers (   $value)

Set to receive output headers in all output functions.

Parameters
booleantrue to include all response headers with output, false otherwise public
Curl_HTTP_Client::send_multipart_post_data (   $url,
  $postdata,
  $file_field_array = array(),
  $ip = null,
  $timeout = 30 
)

Send multipart post data to the target URL return data returned from url or false if error occured (contribution by vule nikolic, vule@.nosp@m.dink.nosp@m.e.net)

Parameters
stringurl
arrayassoc post data array ie. $foo['post_var_name'] = $value
arrayassoc $file_field_array, contains file_field name = value - path pairs
stringip address to bind (default null)
inttimeout in sec for complete curl operation (default 30 sec)
Returns
string data public
Curl_HTTP_Client::send_post_data (   $url,
  $postdata,
  $ip = null,
  $timeout = 10 
)

Send post data to target URL return data returned from url or false if error occured.

Parameters
stringurl
mixedpost data (assoc array ie. $foo['post_var_name'] = $value or as string like var=val1&var2=val2)
stringip address to bind (default null)
inttimeout in sec for complete curl operation (default 10)
Returns
string data public
Curl_HTTP_Client::set_cookie (   $cookie)

Set custom cookie.

Parameters
stringcookie public
Curl_HTTP_Client::set_credentials (   $username,
  $password 
)

Set username/pass for basic http auth.

Parameters
stringuser
stringpass public
Curl_HTTP_Client::set_proxy (   $proxy)

Set proxy to use for each curl request.

Parameters
stringproxy public
Curl_HTTP_Client::set_referrer (   $referrer_url)

Set referrer.

Parameters
stringreferrer url public
Curl_HTTP_Client::set_user_agent (   $useragent)

Set client's useragent.

Parameters
stringuser agent public
Curl_HTTP_Client::store_cookies (   $cookie_file)

Set file location where cookie data will be stored and send on each new request.

Parameters
stringabsolute path to cookie file (must be in writable dir) public

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