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?
The only way I have managed this was using nested templates, and removing the adsense - an easier way would be good!!
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...
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.
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)
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.
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"> PHP:
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.
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.
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?
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?
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; PHP: at top, and put these lines at end if ($noadsense <> 1){ $adsense = '<your adsense code. ..'; } else{ $adsense = ''; } $template = str_replace('{ADSENSE}', $adsense ,$template); PHP:
Thanks for all the help. I contacted the guys that wrote Coppermine and they gave me an excellent fix, that works perfectly!