Host disabled allow_url_fopen function globally.

Discussion in 'Co-op Advertising Network' started by dakar, May 1, 2005.

  1. #1
    The host for most of my sites (dreamhost) that I have the coop running on claims to have globally disabled the allow_url_fopen PHP function that is sposed to kill the file_get_contents function in the ad_network.php scripts.

    Rather it's resulting in a few 'Warning: file_get_contents(): URL file-access is disabled in the server configuration' errors on some pages, but adds are still displaying, guess their attempts to squash the function aren't as good as they expected.

    None the less, they are recommending replacing the file_get_contents with a curl function instead, something like;

    $curl_handle = curl_init();
    // Where should we get the data?
    curl_setopt ($curl_handle, CURLOPT_URL, ‘http://example.com’);
    // This says not to dump it directly to the output stream, but instead
    // have it return as a string.
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    // the following is optional, but you should consider setting it
    // anyway. It prevents your page from hanging if the remote site is
    // down.
    curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
    // Now, YOU make the call.
    $buffer = curl_exec($curl_handle);
    // And tell it to shut down (when your done. You can always make more
    // calls if you want.)
    curl_close($curl_handle);
    // This is where i’d probably do some extra checks on what i just got.
    // Paranoia pays dividends.
    print $buffer;
    Code (markup):
    My question, how bad am I going to screw things up by hacking the script to use the curl function in the script? Will my sites fail validation (IF I can get it to work)??
     
    dakar, May 1, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    It should work...
     
    digitalpoint, May 1, 2005 IP
  3. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    Thanks, I'll start digging into it tomorrow and see if I can wrap my head around it a bit to replace the file_get_contents calls.

    If anyone with more programming skills wants to jump in and take a stab at it before I start hacking on it and save the migraine pills for me I'd sure appreciate it.
     
    dakar, May 1, 2005 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    I also got around to updating the ad_network PHP file so there is no dependency on URLs being allowed within fopen() and also no dependency on the curl extensions being installed while I was at it.

    So if you grab the newest ad_network PHP file, you should be all good (hopefully).
     
    digitalpoint, May 2, 2005 IP
  5. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #5
    Thanks Shawn, I was having a bit of trouble sorting out how to get the function calls, think there was a declaration or something hosed. I'll take a look at it and give it a whirl tommorrow and see how it works out.
     
    dakar, May 2, 2005 IP
  6. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #6
    Double post.... But new rewritten script does not seem to be populating the ad_network_ads file with anything but that magic number and the ip address.

    $cat ad_network_ads_244.txt
    1115094557|216.9.35.51|

    Of course no ads displaying, and validation fails.
     
    dakar, May 2, 2005 IP
  7. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #7
    Hmmm... maybe your server can't communicate with the ad server for whatever reason. What's the IP?
     
    digitalpoint, May 2, 2005 IP
  8. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #8
    The site I tested it from was
    Name: www.hardwarehacking.com
    Address: 205.196.222.85

    I switched it back to the old script last night since it sorta works.... but I just changed it back to the new version for now.

    Thanks!
     
    dakar, May 3, 2005 IP
  9. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #9
    The curl code works with the coop.

    Here's mine...

    
    // start curl hack
    //				$new_ad = file_get_contents ('http://ads.digitalpoint.com/network.php?c=' . $_SERVER['SERVER_NAME'] . '&type=link');
    
    // start curl
    $curl_handle = curl_init();
    
    // set the URL
    curl_setopt ($curl_handle, CURLOPT_URL, 'http://ads.digitalpoint.com/network.php?c=' . $_SERVER['SERVER_NAME'] . '&type=link');
    
    // set the return to buffer
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    
    // set the wait timeout
    curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
    
    // init the buffer and make the call
    $new_ad = "";
    $new_ad = curl_exec($curl_handle);
    
    // check for errors
    $curl_errors = curl_errno($curl_handle);
    
    // finished, close curl
    curl_close($curl_handle);
    
    // see if there was an error or no empty buffer
    if ( $curl_errors || !$new_ad )
    {
    	// make sure we return empty to show cache if errors 
    	$new_ad = "";
    }
    // end curl hack
    
    PHP:
     
    noppid, May 3, 2005 IP
    dakar likes this.
  10. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #10
    Awesome... great job Noppid! Working perfectly now even with the 245 version of the script!

    Thanks a million!
     
    dakar, May 3, 2005 IP
  11. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #11

    Glad it helped ya out. :)
     
    noppid, May 3, 2005 IP