I have a piece of code that is designed to receive any URL and rip it down from the web. So far it's been working fine, until someone gave it this URL:
http://www.aspensurgical.com/static/images/aspen_hill-rom_logo.png
If I hit it from my browser, it shows just fine. But when I try to CURL it down, I get:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /static/images/aspen_hill-rom_logo.png
on this server.</p>
<hr>
<address> Server at www.aspensurgical.com Port 80</address>
</body></html>
The CURL code I'm using is:
$ch = curl_init(str_replace(' ', '%20', $url));
$fh = fopen($local_file, "w");
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);
Is their server somehow realizing I'm not a normal browser and booting me?
They have useragent check to see who you are. Add normal browser's useragent and you should be fine.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
Here's working example in codepad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With