1

Hi there i am using following code to get url data but getting nothing

$url = "http://www.amazon.co.uk/dp/B002P44QH2";
$ch = curl_init();echo $url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
return $page;

When i do print_r(curl_getinfo($ch)) it returns the following output:

    Array
(
    [url] => http://www.amazon.co.uk/dp/B002P44QH2
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0.10347
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 0
    [starttransfer_time] => 0
    [redirect_time] => 0
)

When i do this in terminal it gives me following error

curl -I http://www.amazon.co.uk/dp/B002P44QH2

Error:

curl: (7) Failed to connect to 178.236.5.39: Network is unreachable

Please Help

4
  • do a var_dump() or print_r ton $page Commented Apr 5, 2012 at 12:47
  • This code works fine. Is this a real question? Commented Apr 5, 2012 at 12:53
  • yes mate it is real queston and i think it might have connection error, because when i try to ping any ip address it returns connect: Network is unreachable Commented Apr 5, 2012 at 12:57
  • 2
    The error message you're getting is pretty obvious. You don't have a connection to the internet. There is a finite number of possible explanations for this... I'd start with firewall, anti-virus, etc. first. Commented Apr 5, 2012 at 12:59

1 Answer 1

1

Is it a shared hosting server, if yes then some shared hosting server wont allow curl requests - check this answer for more info https://stackoverflow.com/a/9953646/308251

Sign up to request clarification or add additional context in comments.

1 Comment

it works fine on live server but doesn't work locally. and we have our own server not shared

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.