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)??
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.
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).
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.
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.
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!
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:
Awesome... great job Noppid! Working perfectly now even with the 245 version of the script! Thanks a million!