Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy File get contents is blocked - how can I get around this?

    Hi,

    I'm running scripts on some sites and until now everything is fine. I tried to perform a file_get_contents on this page http://www.superpages.com/bp/New-Yor...0002110663.htm
    and it returns nothing

    other pages on this site do work (but only at higher levels) - such as http://www.superpages.com/bp/New-Yor...0002110663.htm.

    I think this website is blocking the entry to the business information page - how can I get around this?

    Thanks,

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Try using cURL instead. file_get_contents() is ok for very basic calls but i don't think it supports headers and things which the site may be inspecting. cURL lets you set all sets of options.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    shanaschloss (04-22-2011)

  • #3
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    curl init once per script or for each call

    Thanks - it works.

    One more questions - if I have a loop on numerous pages - do I do the curl init for each one or on time per scripts?

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    You only need to use curl_init to initialise a curl instance. You can set the URL in a loop ad call curl_exec as many times as you need.

    This is from php.net:
    PHP Code:
    // create a new cURL resource
    $ch curl_init();

    // set URL and other appropriate options
    curl_setopt($chCURLOPT_URL"http://www.example.com/");
    curl_setopt($chCURLOPT_HEADER0);

    // grab URL and pass it to the browser
    curl_exec($ch);

    // close cURL resource, and free up system resources
    curl_close($ch); 
    Note how you can use curl_setopt() to set the url - which you can do in your loop. Just use curl_init once before the loop and curl_close after the loop.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    shanaschloss (04-22-2011)


  •  

    Tags for this Thread

    Posting Permissions

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