-1

I am using one curl function in my code that returns the html of the given url. It is working fine for all urls. but, for one url it is not fetching the data.

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1000);
        $contents = curl_exec($ch);
        curl_close($ch);
        return $contents;

This is my curl function

My url is 'http://www.example.com/' if i pass the url like this it wont work. if i pass the url without www, then it is working. this is happening for only this particular url.

Gireesh Doddipalli
  • 490
  • 2
  • 9
  • 29

1 Answers1

0

It's possible that this server doesn't have a www sub domain set up, or that it's set up to redirect to the domain with no subdomain (http://example.com). Have you tested that domain in your browser?

Anyhow, try adding

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

And curl will follow any redirects.

JAL
  • 21,295
  • 1
  • 48
  • 66