GIDNetwork > Setting the "no_adsense_for_me" cookie
Register
« AdSense ad_client id dynamically Get the date / time difference with PHP »

Setting the "no_adsense_for_me" cookie

by: JdS - May 27, 2005

As soon as I finished writing the custom PHP functions for generating my AdSense javascript codes dynamically, I had to create a new and secret web page where only I could access it. This secret web page will allow me to set the "no_adsense_for_me" cookie easily.

Of course, I am not going to tell you where it is on this or on my other web sites :P

To make things easier for me to explain, let's assume I have it saved at http://www.gidnetwork.com/nafm.php. Here's what it looks like:

PHP Code Example:



<?php
/**
 * filename        /nafm.php
 */

// ---------------------------------------------
// Set the following variables where appropriate
// ---------------------------------------------
    //                            The domain name where this file resides. e.g. "example.com".
    $_adsense['domain']        =    'gidnetwork.com';
// ---------------------------------------------

include_once( '/home/jds/shared/functions/functions_adsense.php' );



/********** NOTHING TO EDIT BELOW **********/
/*******************************************/

if( isset($_REQUEST['p']) )
{
    $_REQUEST['p']    =    trim$_REQUEST['p'] );
    if( $_REQUEST['p'] === $_adsense['password_to_set_cookie'] )
    {
        if( isset($_GET['set']) )
        {
            if( $_GET['set']==)
            {
                setcookie$GLOBALS['_adsense']['siteowner_cookiename'], null0'/'".{$_adsense['domain']});
            }
            else
            {
                setcookie$GLOBALS['_adsense']['siteowner_cookiename'], 1time()+(3*365*24*60*60), '/'".{$_adsense['domain']});
            }
            die( header("location:$_SERVER[PHP_SELF]?p={$_REQUEST['p']}") );
        }
        else
        {
            adsense_display_cookie_setting_message();
        }
    }
}



/********** SOME REQUIRED FUNCTIONS **********/
/*********************************************/

function adsense_display_cookie_setting_message()
{
    if( isset($_COOKIE$GLOBALS['_adsense']['siteowner_cookiename'] ]) )
        _adsense_display_cookie_isset_message();
    else
        _adsense_display_cookie_notset_message();
}

function _adsense_display_cookie_notset_message()
{
    echo    '<div style="font:600 14px arial,helvetica,sans-serif;">' .
            '<p>AdSense ads are shown with YOUR adsense <var>google_ad_client</var> id.<br />' .
            '<span style="color:red;">You <b>must not click</b> the ads on this web site.</span></p>' .
            "<p><b><a href="$_SERVER[PHP_SELF]?p={$_REQUEST['p']}&amp;set=1">Set the siteowner's cookie now</a>?</b></p>" .
            '</div>';
}

function _adsense_display_cookie_isset_message()
{
    echo    '<div style="font:600 14px arial,helvetica,sans-serif;">' .
            '<p>AdSense ads are shown with the CA-TEST <var>google_ad_client</var> id.<br />' .
            '<span style="color:green;">You <b>can click</b> the ads on this web site.</span></p>' .
            "<p><a href="$_SERVER[PHP_SELF]?p={$_REQUEST['p']}&amp;set=0">Delete cookie</a>?</p>" .
            '</div>';
}
?>


I needed to upload a copy of this file to each domain that I manage. So assuming I wanted to upload a similar file to GIDForums, my other website, I'd simply copy the entire file and edit this bit:

PHP Code Example:


<?php
// ...
// ---------------------------------------------
// Set the following variables where appropriate
// ---------------------------------------------
    //                            The domain name where this file resides. e.g. "example.com".
    $_adsense['domain']        =    'gidforums.com';
// ---------------------------------------------

//...
?>


Save the file and upload it to http://www.gidforums.com/nafm.php!

If you have been paying attention, inside the functions-adsense.inc.php file previously, I set a password; it was "P4Ssw0Rd".

To access any of these nafm.php pages now, all I need to do is to open the browser and visit any one of the following pages, including that password in the URL:

http://www.gidnetwork.com/nafm.php?p=P4Ssw0Rd
http://www.gidforums.com/nafm.php?p=P4Ssw0Rd
http://www.gidsearch.com/nafm.php?p=P4Ssw0Rd

and I have a simple and convenient way to set or delete the "no_adsense_for_me" cookie for each domain.

Would you like to comment? This story has been viewed 10,225 times.
« AdSense ad_client id dynamically Get the date / time difference with PHP »

__top__

Copyright © GIDNetwork™ 2001 - 2024

Another website by J de Silva

Page generated in : 0.00523 sec.