CURL

From Sandoz

(Difference between revisions)
Jump to: navigation, search
(==)
Line 13: Line 13:
3) Cookie
3) Cookie
-
======
+
----------------------
curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation);
curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation);
curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);
curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);

Revision as of 01:33, 14 December 2010

1) Init


$s = curl_init(); curl_setopt($s,CURLOPT_URL,$this->_urlToOpen); curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:')); curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);

2) How many redirection you want to follow


curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects); curl_setopt($s,CURLOPT_RETURNTRANSFER,true); curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);

3) Cookie


curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation); curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);

4) Authentication


curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);

5) Send post variables


curl_setopt($s,CURLOPT_POST,true); curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);

6)Include the header


curl_setopt($s,CURLOPT_HEADER,true);

7) Include the body


curl_setopt($s,CURLOPT_NOBODY,true);

8) Add user agent and referer


curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent); curl_setopt($s,CURLOPT_REFERER,$this->_referer);

9) Execute


$this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE); $this->_error = curl_error($s);

        curl_close($s);

10) Using a proxy


curl_setopt($s, CURLOPT_PROXY, $this->_proxy); curl_setopt($s, CURLOPT_PROXYPORT, $this->_port); curl_setopt ($s, CURLOPT_PROXYUSERPWD, $this->_pass);

Personal tools