View Full Version : Removing Adsense Code on certain pages
Crusader
May 25th 2005, 12:39 pm
My Javascript knowledge is next to none. One of my sites uses a template to function, and I can only include the Adsense code in this template file. The problem is that causes the adsense ads to be displayed on all pages including the login.php and register.php files, which is against Google ToS, which I don't want to break.
I'm looking for a way to exclude a section of HTML code, if the filename is login.php or register.php.
Is there some way this can be done using Javascript?
Jim bob 9 pants
May 25th 2005, 12:44 pm
The only way I have managed this was using nested templates, and removing the adsense - an easier way would be good!!
KMxRetro
May 25th 2005, 12:56 pm
If the files are PHP - as the extension suggests - at the top of your register.php and login.php, put something like this:-
$noadsense = 1;
Then, replace your adsense code with this:-
<?
if ($noadsense <> 1) {
?>
//PUT YOUR ADSENSE CODE HERE
<?
}
?>
On any page you don't want adsense ads to show, just pop that first piece of code in. Not javascript, but hey... :)
Crusader
May 25th 2005, 1:03 pm
The template file is a HTML file so I don't know if this will still work?
exam
May 25th 2005, 1:16 pm
It depends on how your CMS uses the template files. If it just outputs them as HTML and your pages are parsed by php, then it will work.
tresman
May 25th 2005, 1:23 pm
Search in go a little bit, and using the idea above try to do it using
document.write
or
innerHtml...
(just a tip, no it's your time)
Crusader
May 25th 2005, 1:32 pm
The PHP solution seems to be the best option, but it doesn't work correctly for me. I've added it to the template.html file. When I view the page after it's parsed I get
1) { ?>
Followed by the adsense ad.
This is on a page where the ad is supposed to show.
Jim bob 9 pants
May 25th 2005, 1:41 pm
Perfect, thanks a lot!!!
exam
May 25th 2005, 1:46 pm
The PHP solution seems to be the best option, but it doesn't work correctly for me. I've added it to the template.html file. When I view the page after it's parsed I get
1) { ?>
Followed by the adsense ad.
This is on a page where the ad is supposed to show.
For it to work, *all* pages have to be parsed by php. Care to post your site?
Crusader
May 25th 2005, 2:01 pm
It's the site in my sig. The gallery part at least.
Crusader
May 25th 2005, 3:14 pm
Ok, I got this working with a test page. But after using it in the HTML file, it doesn't seem as if the values from the noadsense variable gets detected from the login.php & register.php files.
I've added the
$noadsense = 1;
at the top of the login.php file
$noadsense = 1;
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/register.php,v $
$Revision: 1.11 $
$Author: gaugau $
$Date: 2005/04/19 03:17:11 $
**********************************************/
define('IN_COPPERMINE', true);
define('REGISTER_PHP', true);
require('include/init.inc.php');
require('include/mailer.inc.php');
if (!$CONFIG['allow_user_registration'] || USER_ID) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
if (defined('UDB_INTEGRATION')) udb_register_page();
// Display the disclaimer
function display_disclaimer()
{
global $CONFIG, $PHP_SELF;
global $lang_register_disclamer, $lang_register_php;
starttable(-1, $lang_register_php['term_cond']);
echo <<<EOT
<form method="post" action="$PHP_SELF">
Crusader
May 25th 2005, 3:33 pm
Arghh.. nothing seems to work. I need help. Perhaps Javascript would be the better option, but I can't seem to be able to make head or tails on how to go about it.
Dejavu
May 25th 2005, 3:58 pm
You should only put the values in .php files.
if the section where your adsense gets included is in a function, you can try to put
$global noadsense;
just after the function decleration.
Crusader
May 25th 2005, 4:08 pm
I've added the $global noadsense; ,but it doesn't make any difference.
Dejavu
May 25th 2005, 4:11 pm
sorry that should be global $noadsense
..
Dejavu
May 25th 2005, 4:16 pm
mm when I look at the source, i see
<?php
global $noadsense;
print "noadsense";
if ($noadsense != 1) {
?>
that means the php didnt get parsed. (iow you put the code in the template file, and it just got included that way)
is the code you posted above the login.php file?
Crusader
May 25th 2005, 4:24 pm
Yes the code above is part of the login.php file.
I also now noticed that it didn't get parsed. Why would that be? I've included the following in my htaccess file " addtype application/x-httpd-php .php .shtml .htm .html" shouldn't that solve the parsing problem?
Dejavu
May 25th 2005, 4:44 pm
Ok, I think I got a solution.
edit the template.html file, remove all the adsense code and instead put only
{ADSENSE}
then edit include/functions.inc.php, and go to the load_template() function
add global $noadsense; at top, and put these lines at end
if ($noadsense <> 1){
$adsense = '<your adsense code.
..';
}
else{
$adsense = '';
}
$template = str_replace('{ADSENSE}', $adsense ,$template);
Crusader
May 27th 2005, 10:41 am
Thanks for all the help. I contacted the guys that wrote Coppermine and they gave me an excellent fix, that works perfectly!
cyanyde
Aug 5th 2006, 9:37 pm
Care to share that fix with us?
Crusader
Aug 6th 2006, 12:52 am
I don't have the code at hand unfortunately. It's specific to Coppermine as well, so if you want you can go and take a look at their forums. You are bound to find the solution still there.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.