Novice instructions for setting up with control panel which has PHP

Discussion in 'Co-op Advertising Network' started by joewood, Mar 4, 2005.

  1. #1
    Thanks to the people who helped walk me through my first setup. Here's the result of what I learned to make it easier on others like myself:

    1. In C-panel Create a file (not a folder/directory) named ad_network_184.php in the main directory of your site (if your

    registered site URL is a sub-directory of the domain, it should go in that sub-directory):

    Edit this file and place this copy within the file:

    --------------

    <?php
    // Last update: Feb 22, 2005 2:18 pm

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

    ?>

    ----------------

    2. Create an empty file (not folder) named ad_network_ads_184.txt in the same directory. The web server user MUST have write

    permissions to this file. An easy way to set the permissions would be with the following command. To do this, click on the

    ad_network_ads_184.txt file and on the right side of the screen change the settings to all sevens. Or, if an option, check

    all boxes to make all files writable for Group, World, etc. This will make the chmod as 777 for the ad_network_ads_184.txt

    file. This will make the file writable.


    3. Create a new file (not folder) and name it .htaccess (no prefix) in the main directory for your site with the following

    contents (you can skip this if your site is already PHP based or if your files have .SHTML extensions):

    ---------
    AddType application/x-httpd-php .php .htm .html
    ---------

    4. For a PHP based site (skip this if your site is SHTML based), you *MUST* add the following php code to all of your pages

    (if you have a header/footer you could add it to that one file) (this may be done in Frontpage or your editing software):

    --------

    <?php
    ini_set ("include_path", ini_get ("include_path") . ':../:../../:../../../:../../../../');
    include ('ad_network_184.php');
    echo $ad_network[0];
    ?>

    --------

    Note: If your files are in sub-directories, you may need to use the full path to the ad_network_184.php file.
    If they are already PHP files, you will not need the opening/closing PHP tags.
    If you would like extra weight, you can run multiple ads per page (up to 5) by using additional $ad_network variables, for

    example $ad_network[1], $ad_network[2], etc. (you may want to add some spacing to format the ads).


    5. Once it's setup on your site, request a validation of your site to get your ads into the rotation. If you need any help

    setting anything up, please visit the forum.
     
    joewood, Mar 4, 2005 IP