Jump to content

curl issue


BillyT

Recommended Posts

Hi all

 

using a script that I got from the seo with php book

 

http://www.seoegghead.com/blog/professional-seo-with-php-book

 

It attempts to populate a database with the data provided by the friendly people at iplists.com

 

However, it is failing due to a curl issue and I am unsure what the problem is.  curl is enabled on the server (mediatemple gridserver)

 

basic code

 

  $ch = curl_init();    
    curl_setopt ($ch, CURLOPT_URL, 'http://www.iplists.com/nw/google.txt');

    curl_setopt ($ch, CURLOPT_HEADER, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    $result = curl_exec($ch);
echo $result;

 

 

which outputs

 

HTTP/1.1 403 Forbidden Date: Tue, 21 Oct 2008 04:05:44 GMT Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Content-Length: 517 Connection: close Content-Type: text/html; charset=iso-8859-1
Forbidden

You don't have permission to access /nw/google.txt on this server.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

 

Is it an issue with my code, server, the way connections are handled by the external server, or something else?

 

Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/129353-curl-issue/
Share on other sites

So, I figured out that you just have to set the CURLOPT_USERAGENT. This works for me:

 

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17');
curl_setopt($ch, CURLOPT_URL, 'http://iplists.com/nw/google.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
echo "<pre>$result</pre>";
?>

 

In this case I used Firefox, but you could probably use anything you want.

Link to comment
https://forums.phpfreaks.com/topic/129353-curl-issue/#findComment-670638
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.