Need to get this fixed so its right

Discussion in 'Co-op Advertising Network' started by gchaney, Feb 22, 2005.

  1. #1
    OK, this is working for me, but...I need to get it set up so it is working the way it should.

    I am running SHTML on the site. I am trying to run 5 text links. it is running 5 but the first and last are always the same. I just know there is an easy fix or right way to do this and probably just cleanly eliminating the load command line for the one adv. originating from the main file.

    each page has the following:

    <!--#include virtual="tinkle.php" -->

    this pulls the http://www.downpaymentsolutions.com/tinkle.php file. If you click on the link you'll note it is loading 4 advertisements. ( The fifth comes from the main "tinkle_king.php" file. )

    The tinkle.php code is:

    <?php
    	ini_set ("include_path", ini_get ("include_path") . ':../:../../:../../../:../../../../');
    	include ('tinkle_king.php');
    	echo ' | '.$ad_network[1].' | '.$ad_network[2].' | '.$ad_network[3].' | '.$ad_network[4];
    ?>
    Code (markup):
    Now, this code is pulling from the "tinkle_king.php" file which has this code:

    <?php
    	// Last update:  Jan 21, 2005 8:51 am
    
    	if (!function_exists('file_get_contents')) {
    		function file_get_contents($url) {
    			$handle = fopen($url, 'r');
    			$string = fread($handle, 4096000);
    			fclose($handle);
    			return $string;
    		}
    	}
    	
    	if (!function_exists('make_seed')) {
    		function make_seed() {
    			list($usec, $sec) = explode(' ', microtime());
    			return (float) $sec + ((float) $usec * 100000);
    		}
    		mt_srand (make_seed());
    	}
    
    	if (!isset($_SERVER)) $_SERVER = $HTTP_SERVER_VARS;
    
    	$ad_file = 'princess_sophia.txt';
    	for ($i = 0; $i <= 11; $i++) {
    		$p = substr ('../../../../../../../../../../', 0, $i * 3);
    		if (file_exists ($p . $ad_file)) {
    			$ad_file = $p . $ad_file;
    			break;
    		}
    	}
    
    	if (is_writable ($ad_file)) {
    		$ads = file_get_contents ($ad_file);
    		$ads = explode ('<ad_break>', $ads);
    		$ads_temp = explode ('|', $ads[0]);
    
    		$file = fopen($ad_file, 'r+');
    		if (flock ($file, LOCK_EX|LOCK_NB, $would_block) && !$would_block) {
    			if ((count ($ads) < $ads_temp[3] + 1 && $ads_temp[0] + $ads_temp[5] < time()) || $ads_temp[0] + $ads_temp[4] < time()) {
    				$new_ad = file_get_contents ('http://ads.digitalpoint.com/network.php?b=' . $_SERVER['SERVER_NAME'] . '&type=link');
    				if ($new_ad) {
    					$ads_param = explode ('<ad_param>' , $new_ad);
    					$new_ad = $ads_param[1];
    					unset ($ads_param[1]);
    					$ads_temp = explode ('|', $ads_temp[0] . '|' . $ads_temp[1] . '|' . $ads_param[0]);
    				} else {
    					$ads_param = array_slice ($ads_temp, 2, 4);
    				}
    				$ads[0] = time() . '|' . gethostbyname('validate.digitalpoint.com') . '|' . implode ('|', $ads_param);
    				if ($new_ad) {
    					$ads[] = $new_ad;
    					if (count ($ads) > $ads_temp[3] + 1) $ads = array_merge ((array)$ads[0], (array)array_slice ($ads, -$ads_temp[3]));
    				}
    				fwrite ($file, implode ('<ad_break>', $ads));
    				ftruncate ($file, ftell($file));
    				$ad_network[] = $new_ad;
    			}
    			flock ($file, LOCK_UN);
    			fclose ($file);
    		}
    		while (count ($ad_network) < 5) {
    			$ad_network[] = $ads[mt_rand(1,count($ads) - 1)];
    		}
    		foreach ($ad_network as $key => $ad) {
    			if ($ads_temp[1] == $_SERVER['REMOTE_ADDR'] || $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR']) {
    				$ad_network[$key] = str_replace ('" />', '" class="' . $ads_temp[2] . '" />', $ad);
    			} else {
    				$ad_network[$key] = str_replace ('" />', '">', $ad);
    			}
    		}
    	} else {
    		$ad_network[] = 'You must set the "princess_sophia.txt" file to be writable.';
    	}
    	if (substr (@$_SERVER['DOCUMENT_NAME'], -6) == '.shtml') {
    		ini_set ('zlib.output_compression', 0);
    		echo end ($ad_network);
    	}
    
    ?>
    Code (markup):
    Now this pulls adv. from the princess_sophia.txt file.


    As you can see, I am by no means a PHP writer or would have definitely had this fixed so shawn may need to help with this. However, if you go to the site, you'll see it is running 5 advertisements with the first and last always the same. This is a coding issue and since I hacked this to get more than one advertisement showing I think it just needs some tweaking to get it listing five unique advertisements vs. the present 4/1 ratio.

    Anyone using shtml and running 5 text only advertisements that may have a "correct" method to do this? I'm sure I can work through the code to fix it, but hate investing the time to correct this if someone else has already done it...lol

    Thanks for your help!


    Cheers
     
    gchaney, Feb 22, 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
    I see 4 ads, none of which are the same.
     
    digitalpoint, Feb 23, 2005 IP