Forum Moderators: coopster

Message Too Old, No Replies

file get contents does not work when reading pages from 'mydomain.com'

it works with 'google.com'

         

guarriman

10:44 am on Mar 6, 2007 (gmt 0)

10+ Year Member



Hi.

Working on Linux, I created this script:
---
$url = "http://www.mydomain.com";
$html = @file_get_contents($url, "r") or die("Can't open URL");
echo $html;
-----

This script:
- works ok on my PC box (PHP 4.4.5) with 'http://www.google.com'
- works ok on my PC box (PHP 4.4.5) with 'http://www.mydomain.com'
- works ok on my server (PHP 4.4.2) with 'http://www.google.com'
- DOES NOT work on my server (PHP 4.4.2) with 'http://www.mydomain.com'

Does anybody have any tip to find out why I can't read 'http://www.mydomain.com' on my server? Must I modify something on my 'mydomain.com' server (I manage it)?

Thank you very much.

eelixduppy

11:14 am on Mar 6, 2007 (gmt 0)



Try something like this and see what you get:

error_reporting(E_ALL);
$url = "http://www.mydomain.com";
$html = file_get_contents([url=http://us2.php.net/manual/en/function.urlencode.php]urlencode[/url]($url)) or die("Can't open URL");
echo $html;

joelgreen

1:36 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



Why do you pass "r" argument? Second parameter is not file open mode.

>> file_get_contents($url, "r")

guarriman

9:50 am on Mar 7, 2007 (gmt 0)

10+ Year Member



Hi.

The problem is that 'mydomain.com' is hosted within *THE SAME* server as 'test.php'.

Can 'file_get_contents' get contents from the same server?

eelixduppy

12:38 pm on Mar 7, 2007 (gmt 0)



>> Can 'file_get_contents' get contents from the same server?

Yes, and in fact it doesn't have to be a URI, either. You can just have a relative path:

/path/to/file.html
.