Trying to get the content of the a certain URL using cURL and PHP.
The code is supposed to run on the sourceforge.net project web hosting server.
code:
<?php
function get_data($url)
{
$ch = curl_init();
$timeout = 10;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url1 = urlencode("http://www.google.com");
$url2 = "http://www.google.com";
$output = get_data($url2);
echo $output;
?>
I’ve checked that cURL is supported. But the above code is not working, the page is loading till timeout with no output. I’ve tried the encoded url as well. Why?
Error 503 Service Unavailable. PHP version 5.3.2
I replaced my curl code with yours and its not working. I tried with ‘gmail.com’ and it showed fine with my code and with yours it gave a ‘301 Moved’ Error.
My Code is as follows: