You are not logged in.
Pages: 1
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
Check that the PHP setting allow_url_fopen is set to On. Use phpinfo() to check all settings. And your firewall
Offline
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
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
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
Pages: 1