file ('http://'); not working

Discussion in 'Technology' started by Mirage, Sep 5, 2006.

  1. Mirage

    Mirage Administrator Staff Member V.I.P.

    Hopefully this is simple. I am trying to pull an outside webpage into an array in PHP in order to take values from it..

    I have tried this as described on

    $lines file('');
    The page just stalls and eventually doesn't do anything. I have a line "done" set to be echoed at the end of the page which also does not appear when I add the above code.

    I'm running this on a Windows server with IIS 6.0.

    The page I am getting this info from is:

    The tip on says:

    I have enabled "allow_url_fopen" as well.

    I can load local files, but just not remote files. Any ideas?

    Thanks! :)

  2. Mr_Snipes

    Mr_Snipes Registered Member

    Did you enable "allow_url_fopen" in php.ini only?
  3. Mirage

    Mirage Administrator Staff Member V.I.P.

    Only in php.ini.. Was there somewhere else I need to enable it?
  4. Mr_Snipes

    Mr_Snipes Registered Member

    No, that is the only place you can enable it. Just checking to make sure that you did that one, just in case you had not done that yet.
  5. Spinlock

    Spinlock Registered Member

    What are you using to separate the elements in the array?
  6. Mirage

    Mirage Administrator Staff Member V.I.P.

    It didn't matter because it didn't create the array in the first place due to "file" not working.

    I have since created an alternative function to do this, but it still bugs me that I can't get the built in function working.
  7. Spinlock

    Spinlock Registered Member

    Okay... let me put it this way.
    Does the function work if you just point it to a webpage with EXACTLY one element in it?
    Have you tried echoing the content of $lines directly after that line?
    Last edited: Sep 17, 2006
  8. myessence

    myessence Registered Member

    I've had this happening to me with a few websites.

    Turned out I need to set a user_agent on php.ini. Preferably, to a popular one (eg: IE6, Firefox 1.5.x, etc)

    A few examples :

    // user_agent="Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)"
    // alternatives:
    // "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
    // "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
    // "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"
    // "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"

    In another case, increasing default_socket_timeout to 600 helps, especially with those REALLY slow websites :)

    Hope it helps.

Share This Page