I have the following code: <? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/'); $data = curl_exec($ch) or die("Curl exe failed"); echo $data; curl_close($ch); ?> Code (markup): It works fine, it returns the google homepage, but if I try and add this line: curl_setopt($ch, CURLOPT_PROXY, '103.10.110.37:8080'); Code (markup): IT DOESN'T WORK. Why? Can someone pleeaase help me ? I spend my last 2 hours trying to figure out what the h... is going on.
I have found a manual, with this example you can download content but you can use this how you need. Function: <?php function getPage($proxy, $url, $referer, $agent, $header, $timeout) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_USERAGENT, $agent); $result['EXE'] = curl_exec($ch); $result['INF'] = curl_getinfo($ch); $result['ERR'] = curl_error($ch); curl_close($ch); return $result; } ?> What is each thing? PHP cURL functions used curl_init - initializes a cURL session. curl_setopt - sets and option for a cURL transfer. curl_exec - performs a cURL session. curl_getinfo - gets information about the last transfer. curl_error - returns a string containing the last error for the current session. curl_close - close a cURL session. curl_setopt options used CURLOPT_URL - the URL to scrap. CURLOPT_HEADER - inlude/exclude the header? CURLOPT_RETURNTRANSFER - return the transfer as a string or output it out directly? Use 1, i.e. return. CURLOPT_PROXY - the HTTP proxy to tunnel request through. CURLOPT_HTTPPROXYTUNNEL - tunnel through a given HTTP proxy? Use 1, i.e. tunnel. CURLOPT_CONNECTTIMEOUT - it's obvious. CURLOPT_REFERER - header to be used in a HTTP request. CURLOPT_USERAGENT - "User Agent:" to be used in a HTTP request. Now, how to call this function? <?php $result = getPage( '[proxy IP]:[port]', // use valid proxy 'http://www.google.com/search?q=twitter', 'http://www.google.com/', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8', 1, 5); if (empty($result['ERR'])) { // Job's done! Parse, save, etc. // ... } else { // Captcha or network problems? // ... } ?> It's easy, i have tested that and works perfect. PD: If proxy not works will show you a error, try looking for others proxys and test.