CURL

From Sandoz

(Difference between revisions)
Jump to: navigation, search
m (Protected "CURL" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
 
(6 intermediate revisions not shown)
Line 1: Line 1:
1) Init
1) Init
-
===============
+
-----------
-
$s = curl_init();
+
        $s = curl_init();
-
curl_setopt($s,CURLOPT_URL,$this->_urlToOpen);
+
        curl_setopt($s,CURLOPT_URL,$this->_urlToOpen);
-
curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:'));
+
        curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:'));
-
curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);
+
        curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);
2) How many redirection you want to follow
2) How many redirection you want to follow
-
=======================================
+
--------------------------------------------
-
curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects);
+
        curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects);
-
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
+
        curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
-
curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);
+
        curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);
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);
4) Authentication
4) Authentication
-
===============
+
----------------------
-
curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);
+
        curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);
   
   
5) Send post variables
5) Send post variables
-
===================
+
----------------------
-
curl_setopt($s,CURLOPT_POST,true);
+
        curl_setopt($s,CURLOPT_POST,true);
-
curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);
+
        curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);
6)Include the header
6)Include the header
-
-================
+
----------------------
-
curl_setopt($s,CURLOPT_HEADER,true);
+
        curl_setopt($s,CURLOPT_HEADER,true);
7) Include the body
7) Include the body
-
================
+
----------------------
-
curl_setopt($s,CURLOPT_NOBODY,true);
+
        curl_setopt($s,CURLOPT_NOBODY,true);
8) Add user agent and referer
8) Add user agent and referer
-
==========================
+
---------------------------------
-
curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent);
+
        curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent);
-
curl_setopt($s,CURLOPT_REFERER,$this->_referer);
+
        curl_setopt($s,CURLOPT_REFERER,$this->_referer);
9) Execute
9) Execute
-
==========
+
-----------
-
$this->_webpage = curl_exec($s);
+
        $this->_webpage = curl_exec($s);
-
$this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE);
+
        $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE);
-
$this->_error = curl_error($s);
+
        $this->_error = curl_error($s);
         curl_close($s);
         curl_close($s);
10) Using a proxy
10) Using a proxy
-
=============
+
----------------------
-
curl_setopt($s, CURLOPT_PROXY, $this->_proxy);
+
        curl_setopt($s, CURLOPT_PROXY, $this->_proxy);
-
curl_setopt($s, CURLOPT_PROXYPORT, $this->_port);
+
        curl_setopt($s, CURLOPT_PROXYPORT, $this->_port);
-
curl_setopt ($s, CURLOPT_PROXYUSERPWD, $this->_pass);
+
        curl_setopt ($s, CURLOPT_PROXYUSERPWD, $this->_pass);

Latest revision as of 01:41, 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