Results 1 to 15 of 15

Help with this code for Adsense

This is a discussion on Help with this code for Adsense within the Ad Networks forums, part of the Monetizing category; I don't want my Google ads to be displayed on a certain domain when my website is viewed on that ...

  1. #1
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times

    Question Help with this code for Adsense

    I don't want my Google ads to be displayed on a certain domain when my website is viewed on that said domain.


    Are these codes able to prevent that from happening, if so, where do put them?

    PHP Code:
     If(str_replace('www.'''$_SERVER['server_name']) == $domain)
    {
        die();

    PHP Code:
     function display_adsense()
    {
        If(
    str_replace('www.'''$_SERVER['server_name']) == $domain)
        {
            return 
    FALSE;
        }
        else
        {
            return 
    TRUE;
        }


    PHP Code:
     if(display_adsense())
        echo 
    "adsense code";


  2. #2
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    i would turn this into a plugin, and then use a template conditional.

    plugin code:

    Code:
    
    $adsensevar = true;
    
    if(str_replace('www.', '', $_SERVER['server_name']) == $domain)
    {
        $adsensevar = false;
    }
    
    



    and in your template:

    <if condition="$adsensevar == true">
    SHOW AD CODE
    </if>


    gloabl start is probably the hook you want to use

  3. #3
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Well, I'm looking at a script in the .htaccess file to redirect them as I was told the .htaccess is the first thing that "reads" where traffic is coming from.


    Is this correct?

  4. #4
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Quote Originally Posted by briansol View Post
    i would turn this into a plugin, and then use a template conditional.

    plugin code:

    Code:
    
    $adsensevar = true;
    
    if(str_replace('www.', '', $_SERVER['server_name']) == $domain)
    {
        $adsensevar = false;
    }
    
    



    and in your template:

    <if condition="$adsensevar == true">
    SHOW AD CODE
    </if>


    gloabl start is probably the hook you want to use


    What will this code do?

    Will it prevent Google ads from showing up in whatever domain I don't want them to show up even if my site is listed in that domain.

  5. #5
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Hey,

    Is "$domain"


    where I put the domain that I don't want to see the Google Ads.

    Example,

    $yourdomain.com

    If this is in the code, then it will not show Google ads to yourdomain.com, right?

  6. #6
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    You don't need to use htaccess for this at all. The template conditional will handle it.

    if the variable is not set, nothing will print, and hence, no ad.


    this means if the current server putting in the page request == $domain, then set the var to false, so ads don't show.

    and be sure to set the variable above the if statement.

    $domain = "yourdomainthatyoudontwantadson.com";

  7. #7
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times

    Talking

    Oh ok, thank bro!

    Much appreciated.

  8. #8
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    I did a plugin for this, but it did not display the Adsense at all....lol..

    Any idea what I did wrong?

  9. #9
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    This is what I came up with.

    $domain="puremarketprofits.com"

    The $domain code did not seem to work, so I tried this and it worked.


    When I wrap this code around my adsense, it does not display ads on my domain.

    <if condition="$domain == puremarketprofits.com">


    Google Ads here

    </if>


    Is there any particular reason why it works like this and not just simply using this "$" ?


    I also had to switch around the "false" and "true".


    This is so cool.

    Thanks!

  10. #10
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    did you forget the smicolon?

    $domain = "puremarketprofits.com";

  11. #11
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Yes, I did...lol.

    Thanks.

    I'm new to coding.



  12. #12
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Hey, it didn't work.

    The domain name shows up on the outside of my forum after I included the semicolon.


    This is what I have in the plug-in code, is it correct?

    PHP Code:
    $adsensevar false

    if(
    str_replace('www.'''$_SERVER['server_name']) == $domain

        
    $adsensevar true


  13. #13
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    I found the proper .htaccess rewrite code to solve my problem. Here it is:

    This code is for multiple referrer that you want to block

    Code:
    RewriteEngine on
    # Options +FollowSymlinks
    RewriteCond &#37;{HTTP_REFERER} badsite\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} anotherbadsite\.com
    RewriteRule .* - [F]
    This code here is for one referrer to block

    Code:
    RewriteEngine on
    # Options +FollowSymlinks
    RewriteCond %{HTTP_REFERER} badsite\.com [NC]
    RewriteRule .* - [F]
    If this works, I will keep it as it is rather urgent that I set this up at my board.

    Thanks for all of your help.
    Last edited by MarketTimes; 04-06-2007 at 04:19 AM.

  14. #14
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Hey,

    I have another code, but do not know if it will work.

    Can you tell me if it is right or wrong, please? Thank you.

    Code:
     <?php
    $d = $_SERVER['HTTP_REFERER'];
    if($d=="autosurf.com")
    {
    // block it
    }
    ?>

  15. #15
    Senior Member MarketTimes's Avatar
    Real Name
    MarketTimes
    Join Date
    Nov 2006
    Location
    On Myspace
    Posts
    173
    Liked
    0 times
    Ok, here is the latest update regarding my situation and these pesky traffic exchanges that deliver worthless traffic and puts your Google Adsense account in jeopardy.

    I modified my forum's index.php file and my wordpress blog index.php file and implemented the following codes:

    Code:
    if($_SERVER['HTTP_REFERER']=="badsite.com")
    {
     die();
    }
    if (preg_match('/badsite\.com/', $_SERVER['HTTP_REFERER']))
    {
         exit();
    }
    I tested this on those traffic exchanges and when my site came up, it went blank! This is fantastic!

    Thanks for the help with this potential disaster.

    Another thing, I have both of the codes in my index.php files for my forum and blog portal, but only one of them works. I did not figure out which one works better than the other as my priority was simply to put an end to the situation I was going through.

    If you figure out which code works, please update here. Thank you
    Last edited by MarketTimes; 04-08-2007 at 06:39 PM.

Similar Threads

  1. Finding my Google Analytics Code
    By Michael in forum Troubleshooting
    Replies: 1
    Last Post: 11-21-2005, 03:24 PM
  2. to clean code or not to clean code, that is the question
    By kidmercury in forum Troubleshooting
    Replies: 3
    Last Post: 11-11-2005, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •