You are not logged in.

#1 2010-01-20 04:14:29

murffatksig
Member
From: Atl
Registered: 2004-05-17
Posts: 358

php file_get_contents error

I'm trying to use php to pull data from wikipedia.  Wikipedia has an api (http://en.wikipedia.org/w/api.php), but it's not documented very well.  Using the api, I'm able to get the title of a random page, then I use file_get_contents to get the text of a page so I can display it.  The code looks something like this...

//$link hard coded for example
$link = "http://en.wikipedia.org/wiki/Pasar_Senen_Station";

$page = file_get_contents($link);
echo $page;

For some pages (like the one in the example, it does not work and I get the following error.

Warning: file_get_contents(http://en.wikipedia.org/wiki/Pasar_Senen_Station) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

For other pages, it works fine and displays the page.  Any php devs know what's going on?  I tried adding a context, but that didnt seem to work.  Although, I'm not sure I did it correctly.  Any help is appreciated.

Thanks


"Oh, they have the internet on computers now."

Offline

#2 2010-01-20 20:27:09

n0dix
Member
Registered: 2009-09-22
Posts: 956

Re: php file_get_contents error

Check that the PHP setting allow_url_fopen is set to On. Use phpinfo() to check all settings. And your firewall

Offline

#3 2010-01-20 20:49:51

murffatksig
Member
From: Atl
Registered: 2004-05-17
Posts: 358

Re: php file_get_contents error

n0dix wrote:

Check that the PHP setting allow_url_fopen is set to On. Use phpinfo() to check all settings. And your firewall

allow_url_fopen is set to on.  I verified via phpinfo(), but I didn't really have to because some pages work and some don't.  The fact that some pages work would also tend to rule out the firewall concern.


"Oh, they have the internet on computers now."

Offline

#4 2010-01-20 20:53:03

urist
Member
Registered: 2009-02-22
Posts: 248

Re: php file_get_contents error

Maybe it was a problem on Wikipedia's end. I remember trying your code yesterday and it not working. I just tried again and it works.

Offline

#5 2010-01-20 21:07:17

murffatksig
Member
From: Atl
Registered: 2004-05-17
Posts: 358

Re: php file_get_contents error

Hmm, yea I just noticed the article I orginally hardcoded is working now.  But theres still some random articles that don't work.  I tried again with http://wikipedia.org/wiki/Taquari and it didn't work.  Strange.


"Oh, they have the internet on computers now."

Offline

Board footer

Powered by FluxBB