开发者

loading FB thru PHP file_get_contents() throws 'You are using an Incompatible Web Browser' error

I have PHP hosting with GoDaddy. Lately for last one hour, I am not able to load facebook content from my php scripts as it always says that

'You are using an Incompatible Web Browser'.

I know that it seems to be a browser issue, but i am sure that it is not because I have tried it with firefox+chrome+I开发者_JS百科E on two windows machine and I have tried with Firefox+safari browsers on a mac machine. Its getting the same error every time.

Could you please let me know what could be a possible reason for this?

[Try loading http://cabbie.apprumble.in/index.php?r=site/test]

In normal circumstances, This should load the facebook home page properly, instead of showing the error that You have incompatible browser.

[PS: I am loading the facebook page using php call file_get_contents("http://facebook.com") which was working perfectly fine until an hour back. Also, if I load the url from outside the browser, it works perfectly fine, but if its invoked from within the php using file_get_contents call, the said error appears.)]

Could someone please reply soon as I am stuck in my development due to this.

Thanks, Kshitij


file_get_contents uses the user agent set in your php.ini file from the setting user_agent. You probably cannot change this as you are on godaddy hosting.

You will need to switch from file_get_contents to something that lets you control the user agent. You could use curl or sockets. Here is a curl example:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13'); // set the user agent here

$data = curl_exec($ch);

echo $data;  // this is the homepage

Facebook is attempting to block bots by not allowing certain user agents to request pages. You need to spoof the user agent to look like a normal browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜