i need to open the following url
$file = "http://en.wikipedia.org/w/api.php?action=par开发者_如何学运维se&page=Kundapura&prop=text&format=xml";
$fp = fopen($file, "r");
but i am geeting warning http request failed/ 403 forbidden
The default PHP user agent is blocked; see Wikimedia's User-Agent policy for details. You can easily enough change your user agent using ini_set
at the top of your script, like this:
ini_set("user_agent", "Testing for http://stackoverflow.com/questions/5509640");
Do note that the English Wikipedia forbids downloading many pages via the API (offering database dumps instead), and that automated processes that actually edit the wiki are forbidden unless approved. See their bot policy for details.
What do you need the file for? If you just need the output, you can try file_get_contents() instead, and then load and manipulate it as a string instead of a file.
but i am geeting warning http request failed/ 403 forbidden
The 403 error is coming from their server.
Chances are that you or someone on the IP address or block you are using has been aggressively banned from using the Wikipedia API. You will need to contact a responsible admin at Wikipedia to investigate.
精彩评论