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']==0 )
{
setcookie( $GLOBALS['_adsense']['siteowner_cookiename'], null, 0, '/', ".{$_adsense['domain']}" );
}
else
{
setcookie( $GLOBALS['_adsense']['siteowner_cookiename'], 1, time()+(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']}&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']}&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.