1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP code to hide your own ads enclosed

Discussion in 'AdSense' started by alext, Oct 8, 2005.

  1. #1
    Someone asked me for the code I used to block my own ads. So I thought I would post it here for whoever may find it useful. I have been using this code a few months and I like it since it maintains the layout of the site as if it had the ad imbedded in the page.

    I made changes to the code for public consumption, so there is a possibility of a typo. What I am saying is, test it out on a low profile page before exposing the world to it. :)

    This is code I wrote, use it as you see fit. It is very simple and you may find you want to modify or expand its use.

    Let me know if you find any problems with it.


    <?php
    /*
     *  This code is designed to not show your own Google Adsense
     *  ads while you are surfing your own sites. This prevents
     *  racking up impressions that will skew your stats and prevents
     *  you from clicking your own ads.
     *
     *  I use this code and have had no issue with it what-so-ever
     *  BUT use at your own risk. Test before putting into production!
     *
     *  Usage:
     *    1) Add your Google Adsense code where indicated below.
     *    2) Modify the div styling as needed.
     *    3) Change the table dimensions and styling as needed.
     *    4) Add the IP addresses you wish to block.
     *      On windows you can determine your own IP address by
     *      using the command, ipconfig, at the
     *      command prompt / MS-DOS window.
     *    5) Save this file on your server where ever you wish to.
     *      e.g. http://www.domain.com/ads/ads.inc
     *    6) Insert the following code in your website where you
     *    wish to show your ads.
     *      <?php include 'http://www.domain.com/ads/ads.inc'; ?>
     *
     */
    	$notme = 1;
    	if ($_SERVER["REMOTE_ADDR"] == "my.ip.add.here") $notme = 0;
    	if ($_SERVER["REMOTE_ADDR"] == "other.ip.add.here") $notme = 0;
    	//  Add another if statement here with another IP address if
    	//  you wish to block it as well. You can change this to use
    	//  an array if you have a bigger list.
    	//
    //$notme = 1; // debugging. Uncomment if you want to see the ads
    
    	if ($notme) {
    		?><div style="float: right; margin: 5px 5px 5px 10px;">
    		<!-- replace this comment with your Google Adsense code -->
    		</div><?php
    	} else {
    		//  This is what visitors from the blocked IP addresses
    		//  will see (specified above).
    		//  This shows a table with the dimensions of the ad.
    		//  Change as needed.
    		//
    		?><div style="float: right; margin: 5px 5px 5px 10px;"><table width = "250" height = "250" border = "1"><tr><td>&nbsp;</td></tr></table></div><?php
    	}
    ?>
    Code (markup):
    Edit: typo in the documentation fixed. Nothing serious.
     
    alext, Oct 8, 2005 IP
  2. UndiesHosting

    UndiesHosting Active Member

    Messages:
    219
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #2
    thank you very much for this contribution
     
    UndiesHosting, Oct 8, 2005 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Another way to do it (especially if you have lots of sites) is to simply block googlesyndication.com in your computer's hosts file. But if you want to do it on your server, that's a good bit of code. :)
     
    exam, Oct 8, 2005 IP
  4. shadow213

    shadow213 Peon

    Messages:
    210
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    agree wid exam...i also did it...
     
    shadow213, Oct 10, 2005 IP
  5. durango

    durango Guest

    Messages:
    83
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for the post. Never even thought about doing that, just kept telling myself, don't click, don't click :D
     
    durango, Oct 10, 2005 IP
  6. adfunk

    adfunk Peon

    Messages:
    949
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    wht the hack? if u want to see ur own ads just copy link location and take only the url without clicking the ads, i always do that
     
    adfunk, Oct 21, 2005 IP
  7. dzcap

    dzcap Well-Known Member

    Messages:
    970
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    153
    #7
    An easier way is to just edit your hosts file and block adsense, but it will block all adsense ads, even your competitors. Or you can use firefox to block the ads.
     
    dzcap, Oct 21, 2005 IP
  8. perdrix

    perdrix Peon

    Messages:
    187
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I appreciate the contribution. I wish, since Google doesn't count the click you make (never had with mine) that they wouldn't count the impressions as well... that would resolve the stat integrity issue completely.
     
    perdrix, Oct 21, 2005 IP
  9. dkbtech

    dkbtech Peon

    Messages:
    155
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I tried to block googlesyndication in Firefox, but the ads are still showing up. Where do I put that exclusion for it to be effective (I tried blocking ads).

    Cheers,

    Barry
     
    dkbtech, Oct 21, 2005 IP
  10. MattBeard

    MattBeard Peon

    Messages:
    259
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hey, I used a modified version of your script and it works well.

    I included the text "Google AdSense" centred in the box so I know what lives there.

    Wouln't it be great to be able to set a flag of some sort and see the ads come to life withour having to tiffle the php code?
     
    MattBeard, Dec 31, 2005 IP
  11. medusa

    medusa Peon

    Messages:
    349
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Great script!

    I tested it and it works very well.

    Instead of having a blank table at your IP, you can also have any text/ links/ images in that box. This is especially useful if you are on office LAN where many people have the same IP. Why show blank tables to them? You can as well show them some of your own links...
     
    medusa, Dec 31, 2005 IP
  12. carlox

    carlox Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I wonder why google does not offer an IP blocking feature, e.g. ads appears the same way, as in the preview tool, but no revenue is generated to publisher.

    Another nice feature would be the *automatic* blocking of the IP of the publisher, known in the moment he/she log in to his stats page... mmhhh this can fail when the publisher is behind a proxy (I think to some providers that give a private network IP to their subscriber).
    Anyway, making this feature optional, it could work.

    CarloX
     
    carlox, Jan 17, 2006 IP
  13. alext

    alext Active Member

    Messages:
    406
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    68
    #13
    Good ideas! I will update it when I get the chance.

    Also a good idea. For my situation (and I assume most people) giving users at my same IP address something to do in place of AdSense isn't at all important. But for others this is a nice idea.

    I also think it is strange that Google doesn't just not credit clicks from the publishers IP. They seem fine with silently discounting "fraudulent clicks" (which I think is good) so why not the publishers IP?

    Since I have changed ISPs I now have a random assigned IP address. It doesn't change very often at all (when the modem gets reset) but it doesn't play well with my script. I was thinking of implementing something like you mention above. You set the start page of your web browser to a private script page that automatically logs your current IP address. Now that IP address gets used for blocking the ads. It wopuld have to be centralized to handle mutiple domains / different hosting accounts...

    Just thinking out loud ;)

    I am open to suggestions but I don't want this thing to become to complex to use / install. It was intended to be a simple way of hiding AdSense but not altering the page layout. It isn't phpadsnew after all... :p
     
    alext, Jan 17, 2006 IP
  14. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Are you Alex Tew by any chance?
     
    T0PS3O, Jan 17, 2006 IP
  15. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #15
    For development purposes I'd rather see how my ads look in my pages at all times.

    You never know when something might be causing your ads to display improperly and with this script you never will. IMO

    I also like to see how well my ads are being targetted on each of my pages when I visit them.

    This script hurts more than it helps IMO.
     
    GeorgeB., Jan 17, 2006 IP
  16. alext

    alext Active Member

    Messages:
    406
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    68
    #16
    Not yet. :D
     
    alext, Jan 17, 2006 IP
  17. blackbug

    blackbug Peon

    Messages:
    1,002
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Yeah, I agree with that.

    There's a script for for the firefox greasemonkey extension that disables you being able to click on any ads with your own publisher ID. So you can see it and even try to click on it, but nothing will happen.
     
    blackbug, Jan 17, 2006 IP
  18. alext

    alext Active Member

    Messages:
    406
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    68
    #18
    Many of the sites that I build I visit and interact with on a regular basis. As well, and more importantly, there are a number of other people on my same IP address. I can't risk having them going and clicking my ads from the same IP address can I?

    If this isn't the case for you, then yes, it hurts you more than it helps. For me, I can't agree. When I want to see the ads, it is very easy to toggle them back on.

    Added: The reason that I made this script was to keep other people on my IP address from click my ads.
     
    alext, Jan 17, 2006 IP
    blackbug likes this.
  19. Seiya

    Seiya Peon

    Messages:
    4,666
    Likes Received:
    404
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Can you read? :eek:
     
    Seiya, Jan 17, 2006 IP
  20. carlox

    carlox Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Regarding the showing of real ads for formatting & developing purpose, I know many people put on pages under development the adsense codes but with the test account ("ca-test" if I'm not wrong).

    This use is somewhat controversial because some believe this is a "code modification", forbidden by Google TOS.
     
    carlox, Jan 17, 2006 IP