1

I am trying to simply use file_get_contents() to get content of http://www.google.com/search?hl=en&tbm=nws&authuser=0&q=Pakistan with same code on 2 different servers. One is getting every thing file while other is getting 403 error. I am unable to know what exactly the reason is. I used phpinfo() on both servers.

One difference I observe is that one use apache2 while other use some other HTTP server named LiteSpeed V6.6. But i don't know how if it affect this file_get_contents() method. For more detail you can see their phpinfo() page link below. Where file_get_contents getting 403 the phpinfo is; http://zavahost.com/newsreader/phpinfo.php

while where it is working file , here is the phpinfo: http://162.243.5.14/info.php

I will be thankful if someone can tell that what is effecting file_get_contents()? Please let me know if any idea?

Hafiz
  • 4,187
  • 12
  • 58
  • 111
  • 1
    Some hosters block fetching remote resources. If you're not sure ask your hoster. You can run some tests to see if other methods work, like `fopen` and cURL. – Halcyon Apr 07 '14 at 21:49
  • @Hafiz Is the permission `read` enabled for the file and folder ? – CMPS Apr 07 '14 at 21:50
  • Try fetching another website (non google) to see if you get the same error code. Could be either the host is blocking the request or maybe even google is blocking based on IP because of past abuse (shared hosting with shared IP maybe?). – Jonathan Kuhn Apr 07 '14 at 21:54
  • 403 is an Unauthorized Error. That means you lack sufficient permission to connect to the content at that server. I'm not sure if this could be due to the inability to fetch data from your hosting provider, but it could also be denied based on header information the remote server has flagged as unauthorized. – Eric Uldall Apr 07 '14 at 21:55
  • 1
    Try using the answer on this post: http://stackoverflow.com/questions/2440729/php-curl-how-can-i-emulate-a-get-request-exactly-like-a-web-browser to curl the same data from the server that is getting the 403 – Eric Uldall Apr 07 '14 at 21:56
  • @Doge http://www.google.com is working. Only not working for that news search URL on this server, see exact output: `http://zavahost.com/newsreader/usage_file.php` while it is working on other server. – Hafiz Apr 07 '14 at 21:58
  • Something between you and google is blocking the request. Maybe even google itself. If you abuse their service they might ban you but you need to quite unreasonable before that happens. Another possibility is that your hoster or some in-between proxy is blocking the request. – Halcyon Apr 07 '14 at 22:00
  • 1
    @EricUldall If you can use the same content as answer then I can mark it correct so that you can get some point and others can know that this question is answered and anyone in search can find the solution. – Hafiz Apr 08 '14 at 10:47
  • 1
    @Hafiz I've moved my comments to an answer. – Eric Uldall Apr 10 '14 at 06:52

1 Answers1

0

403 is an Unauthorized Error. That means you lack sufficient permission to connect to the content at that server. I'm not sure if this could be due to the inability to fetch data from your hosting provider, but it could also be denied based on header information the remote server has flagged as unauthorized.

Try using the answer on this post: php curl: how can i emulate a get request exactly like a web browser? to curl the same data from the server that is getting the 403

Community
  • 1
  • 1
Eric Uldall
  • 2,282
  • 1
  • 17
  • 30