For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise. For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise.
Reply content:
For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise.
Http://php.net/manual/en/book.curl.php
php
if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
Function curlPost ($ url, $ post = '', $ autoFollow = 0) {$ ch = curl_init (); $ user_agent = 'safari Mozilla/5.0 (Macintosh; intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/5 curl_setopt ($ ch, CURLOPT_USERAGENT, $ user_agent); // 2. set options, including URL curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); curl_setopt ($ ch, substring, array ('x-FORWARDED-FOR: 61.135.169.125 ', 'client-IP: 61.135.169.125'); // construct IP curl_setopt ($ ch, CURLOPT_REFERER," http://www.baidu.com/ "); // Construct curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get'); if ($ autoFollow) {curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true ); // start the jump link curl_setopt ($ ch, CURLOPT_AUTOREFERER, true); // Multi-Level Automatic jump} // if ($ post! = '') {Curl_setopt ($ ch, CURLOPT_POST, 1); // The post submission method curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post);} // 3. execute and obtain the HTML document content $ output = curl_exec ($ ch); curl_close ($ ch); return $ output ;}
CURLOPT_HTTPHEADER,
Essential for Crawler writing