SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get_file_contents() does not work for localhost

    Hello, I have problem with file_get_contents() in my localhost.
    When i try
    PHP Code:
    echo file_get_contents('http://localhost/index.php'); // it output error of 
    Warningfile_get_contents(http://localhost/index.php) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\www\Apache2\htdocs\test.php on line 2

    // but when i try 
    echo file_get_contents('http://www.google.com/'// it works 
    my http://localhost/index.php just content a string "<h1> It works</h1>"
    Does anybody know why ? I thought my firewall is blocking the connection, so when I disabled my firewall, it still not working. Thanks for any of your help.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What error do you get?
    Do you have allow_url_fopen = On in your php.ini?

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your prompt reply, allow_url_fopen is on. I just found the solution by just echo file_get_contents('index.php'); (without http://localhost/) . Before this I got this error
    Warning: file_get_contents(http://localhost/index.php) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\www\Apache2\htdocs\test.php on line 2


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •