SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question file_get_contents() driving me crazy

    Hi peeps. I have a script which looks like:

    PHP Code:
    $contents file_get_contents($url);
    preg_match("#<a href=\"(.+?)\">${tagcrap}post${tagcrap}to${tagcrap}classifieds${tagcrap}#",$contents,$matches) or die("#<a href=\"(.+?)\">${tagcrap}post${tagcrap}to${tagcrap}classifieds${tagcrap}#");
    $newurl $matches[1];
    $newcontents file_get_contents($newurl);
    echo 
    $newcontents
    Now, it all works until
    PHP Code:
    $newcontents file_get_contents($newurl); 
    I can't tell you the usual value of $newurl because its a very well known website, as well as client-programmer issues.

    anyway, the error i get it:

    Quote Originally Posted by the script
    Warning: file_get_contents(): HTTP request failed! <Ēk in --scriptpath-- on line 24

    Warning: file_get_contents(--url here--): failed to open stream: No error in --scriptpath-- on line 24
    Line 24 is shown above.

    Can anyone tell me why this happens?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sorry if this sounds really obvious, I am sure you tried it but...

    Does echo $newurl show what you expect? does it start with http:// ?

    What happens when you hard code a typical url in place of $newurl ?

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ye, it starts with http://.

    I just tried putting the url of the site and the same error occurs.

    What i really don't get is that the 'file_get_contents($url)' above it works, but the one on link 24 doesn't.

    Please can someone help?

    I really can't give you the url of the page, but its like this:

    "http://post.host.org/dir"

    and i don't know the file name of the index file, or the extension. I dont think that matters.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The content is probably being redirected.....

    I think you might need curl - I think that can follow redirects - I had that working once, but cant get to the code ATM.

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Its quite weird actually. The code works on my localhost, but not on the domain i use for testing scripts. I think this site has a dedicated server though, so they should be able to manage any php.ini details that may need to be set to work properly.

    Thanks for your help cups.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Hi, I am sorry I am not supplying very concrete answers, but it seems very quiet today....

    This could be a security issue emanating from the ini file on the live server.

    Look especially at safe_mode, and what can be included or fetched.

    Off Topic:

    Just dreamt this up: to rule out a firewall issue, upload a page with an iframe containing a link to your secret url - check the page appears

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its also possible that this site is sniffing requests, and denying you if they dont like what they smell.

    maybe you need to send a referer header, or maybe a different user agent string, or maybe a cookie etc...

    see curl or do it by hand with fsockopen()

    a quick n dirty way to see the response headers:
    PHP Code:
    fopen($url'r');
    // this var magically appears
    print_r($http_response_header); 

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You might also wanna check out Snoopy
    Saul

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are fopen-wrappers enabled?


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
  •