i want to get content via a proxy i tried the following code but i dont get the content of proxy ! i get value of redirect but after that i cant echo its content! could any one tell me how to fix it?Thanks in advance.
<?php
//create array of data to be posted
$post_data['u'] = 'http://api.somesite.com/get?apikey=w3ijwiefjdigashdufhsaiufs34r4';
$post_data['encodeURL'] = 'on';
$post_data['allowCookies'] = 'on';
$post_data['stripJS'] = 'on';
$post_data['stripObjects'] = 'on';
//u'
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('http://zend2.com/includes/process.php?action=update');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//i added these two lines
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($curl,CURLOPT_MAXREDIRS,2);//only 2 redirects
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
$info = curl_getinfo($curl_connection);
$url2 = $info['redirect_url'];
echo "redirect_url:".$url2;
echo result;
you need to set the CURLOPT_PROXY to go through a proxy. refer curl documentation for above value.