简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM