Removing Adsense Code on certain pages

Discussion in 'JavaScript' started by Crusader, May 25, 2005.

  1. #1
    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?
     
    Crusader, May 25, 2005 IP
  2. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The only way I have managed this was using nested templates, and removing the adsense - an easier way would be good!!
     
    Jim bob 9 pants, May 25, 2005 IP
  3. KMxRetro

    KMxRetro Peon

    Messages:
    22
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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... :)
     
    KMxRetro, May 25, 2005 IP
  4. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The template file is a HTML file so I don't know if this will still work?
     
    Crusader, May 25, 2005 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    exam, May 25, 2005 IP
  6. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #6
    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)
     
    tresman, May 25, 2005 IP
  7. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    Crusader, May 25, 2005 IP
  8. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Perfect, thanks a lot!!!
     
    Jim bob 9 pants, May 25, 2005 IP
  9. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #9
    For it to work, *all* pages have to be parsed by php. Care to post your site?
     
    exam, May 25, 2005 IP
  10. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It's the site in my sig. The gallery part at least.
     
    Crusader, May 25, 2005 IP
  11. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #11
    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:
     
    Crusader, May 25, 2005 IP
  12. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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.
     
    Crusader, May 25, 2005 IP
  13. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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.
     
    Dejavu, May 25, 2005 IP
  14. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I've added the $global noadsense; ,but it doesn't make any difference.
     
    Crusader, May 25, 2005 IP
  15. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #15
    sorry that should be global $noadsense
    ..
     
    Dejavu, May 25, 2005 IP
  16. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #16
    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?
     
    Dejavu, May 25, 2005 IP
  17. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #17
    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?
     
    Crusader, May 25, 2005 IP
  18. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #18
    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:
     
    Dejavu, May 25, 2005 IP
  19. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Thanks for all the help. I contacted the guys that wrote Coppermine and they gave me an excellent fix, that works perfectly!
     
    Crusader, May 27, 2005 IP
  20. cyanyde

    cyanyde Guest

    Messages:
    131
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Care to share that fix with us?
     
    cyanyde, Aug 5, 2006 IP