multiple adv

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

  1. #1
    Good Day Gang,

    I am updating and running multiple adv. on this site:

    (http://www.)equesthomeloans.com

    I am running this site as shtml

    my code to pull down the file is:
    <!--#include virtual="tinkle.php" -->

    my tinkle file has the following code:

    <?php
    ini_set ("include_path", ini_get ("include_path") . ':../:../../:../../../:../../../../');
    include ('ad_network.php');
    echo $ad_network[0].' | '.$ad_network[1].' | '.$ad_network[2].' | '.$ad_network[3].' | '.$ad_network[4];
    ?>

    and my ad_network.php as 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 = 'ad_network_ads.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 "ad_network_ads.txt" file to be writable.';
    }
    if (substr (@$_SERVER['DOCUMENT_NAME'], -6) == '.shtml') {
    ini_set ('zlib.output_compression', 0);
    echo end ($ad_network);
    }

    ?>

    The good new is it works.

    The bad news is the darn thing is running six adv. and most are duplicate with the first two running together.

    Now, I know nothing about php. I mean Nada and took some experimenting to get the darn thing to do even this. So can someone pretty please tell me what am I doing wrong that needs to be fixed so the adv show up with just 5 unique displays. If you're feeling super nice, maybe copy and paste the right code so I don't screw that up?....lol

    Thanks for your help!

    Cheers
     
    gchaney, Feb 1, 2005 IP
  2. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #2
    it loooks good to me. you might want to specify the full path to tinkle.php (/usr/local/apache/htdocs/tinkle.php or whereever your host directory is) - it could be that there are multiple tinkle.php's out there from your tinkering that are fouling things up.

    Are you sure? When you first start showing ad's, there are a lot of repeats.

    I don't see anything that would kick out 6 ads.
     
    nevetS, Feb 1, 2005 IP
  3. cafemonkey

    cafemonkey Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    In your tinkle file (great name, btw), change this:

    echo $ad_network[0].' | '.$ad_network[1].' | '.$ad_network[2].' | '.$ad_network[3].' | '.$ad_network[4];
    Code (markup):
    to this:
    echo implode (' | ', $ad_network);
    Code (markup):
    And see what you get.

    As far as the duplicates... You will always get some duplicates the first few times you refresh after the ad_network_ads.txt is cleared out. Just refresh a dozen times and it'll go away.
     
    cafemonkey, Feb 1, 2005 IP
  4. crew

    crew Peon

    Messages:
    225
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    "When you first start showing ad's, there are a lot of repeats."

    I'll second that. I don't think the non-unique ads are a problem.

    As for the 6 ads...Check your html source code on the ads. My guess is that it is actually 5 ads, but one of them looks like 2 ads. I vaguely remember something similar a few weeks ago. that's the best I can come up with as the code looks good.
     
    crew, Feb 1, 2005 IP
  5. cafemonkey

    cafemonkey Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No, I'm looking at the site, and it's definately a 6th ad.

    The only indicator I see is that the first one (the rogue ad) doesn't have a pipe after it. So we have:

    Ad1Ad2 | Ad3 | Ad4 | Ad5 | Ad6

    It makes me think there's something ELSE in the original page/template that is calling the ad_network.php file.
     
    cafemonkey, Feb 1, 2005 IP
  6. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Maybe it's not an ad at all, but a link you have placed right before the include statement.

    Post the source of your problem page, and a link to it so we can see a page that has the problem with both the source and resulting views.
     
    nevetS, Feb 1, 2005 IP
  7. gchaney

    gchaney Peon

    Messages:
    144
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK, think I got it under control. Validate good.

    What I think was happening was the tinkle file was calling up the the ad_network.php file which I assume was loading the first advertisement and why six kept showing up with the first two having no spacing.


    this is the code I finally used in my Tinkle file to make it all good:
    <?php
    ini_set ("include_path", ini_get ("include_path") . ':../:../../:../../../:../../../../');
    include ('ad_network.php');
    echo ' | '.$ad_network[1].' | '.$ad_network[2].' | '.$ad_network[3].' | '.$ad_network[4];
    ?>

    (I watched how to lose a guy in ten days last night. One of the little dogs nick names used during the movie was tinkle king....lol)

    Thanks for all your input on this!

    Cheers
     
    gchaney, Feb 1, 2005 IP
  8. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #8
    [​IMG]

    Well I guess that's one way to take care of it. Sometimes it's better to use a hack than to spend 12 hours searching for a mistake. This is really a strange problem.
     
    nevetS, Feb 1, 2005 IP