echo file_get_contents working on some servers but not others

Discussion in 'PHP' started by kroxy, May 26, 2010.

  1. #1
    Hi there,

    If anyone can help me, I would be REALLY grateful.

    I am trying to pull the contents of another website on another server using the "echo file_get_contents('http://domain.com/index.php');" command. This works fine on some of my servers, but on others it does not get anything for 90% of my domains, but does on the other 10%. I have no idea why.

    The page I am trying to load is:

    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    echo file_get_contents('http://domain.com/tos/remote.php?id=3');
    ?>
    
    PHP:


    But if I browse to the page I want to include (http://domain.com/tos/remote.php?id=3') that always loads fine, so the problem is not there.

    thanks in advance for any advice

    Keith
     
    kroxy, May 26, 2010 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    Maybe "allow_url_fopen" is set to "Off"

    The function file_get_contents() will not work if the first parameter is a url and the php ini directive "allow_url_fopen" is "Off"
     
    nabil_kadimi, May 26, 2010 IP
  3. kidatum

    kidatum Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As mentioned by nabil_kadimi there is a way to block the user of file_get_contents() function. There is a way around this though using cURL, header and few other methods. The setup is a little more complex than a simple function like file_get_contents().
     
    kidatum, May 26, 2010 IP
  4. kroxy

    kroxy Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks a lot.

    Thanks to your help problem now fixed.

    The server tech said:

    "The allow_url_fopen is set to on in the sever main php.ini files. So everything should be fine. If you want the custom php.ini files under your domains please get back to us with the domains list so that I can place the custom php.ini files under your all domains"

    But when he put it in the custom php.ini files, the problem miraculously went away!

    Keith
     
    kroxy, May 27, 2010 IP