user3818576
user3818576

Reputation: 3391

404 not found in curl

I have been searching for answer here about 404, but I'm not lucky to solve my problem. I have the same problem in previous post. I already copy and paste their answer but no luck again.

here's my code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$raw_data = curl_exec($ch);
curl_close($ch);

var_dump($raw_data);

I don't know if I have a right code in curl. But if I paste the url in to a browser, I get the result. Is there something that I need to configure or set in my server? I don't know what the cause of this. Do I need to involve server personnel to check on this? Hoping for your advice here. I'm new of this.

Upvotes: 2

Views: 5870

Answers (1)

Adrien
Adrien

Reputation: 1947

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); prevents curl from following redirects. Therefore, if you URL is redirected (from http to https, domain.com to www.domain.com, etc.), it won't work.

The browser, however, does redirect you. Try changing this line to curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);, it should help!

Upvotes: 2

Related Questions