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.

How to hide adsense ads for a specific country?

Discussion in 'PHP' started by KingCobra, Mar 4, 2013.

  1. #1
    My web site is based on PHP-MySQL.
    I have adsense ads in my site.
    I would like to hide adsense ads for the visitors of a specific country (Example: Nepal). So when the visitors of Nepal visit my site they will not see adsense ads on my site.
    Other visitors from other countries will see the ads normally.

    Is it possible? Please tell me the ways. Thank you.
     
    KingCobra, Mar 4, 2013 IP
  2. J.P

    J.P Notable Member

    Messages:
    767
    Likes Received:
    42
    Best Answers:
    3
    Trophy Points:
    205
    #2
    You could always have a php script that checks IP address against a list of known IP addresses (from the specific countries) and store the result.. then just put the ads in a if statement to allow or block depending on IP.. just a quick and random thought
     
    J.P, Mar 4, 2013 IP
  3. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    you need ip to country script.
    you can use maxmind or ip2location API
     
    ogah, Mar 4, 2013 IP
  4. lapidus

    lapidus Active Member

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #4
    I see this threat is a little bit old but maybe someone have solution in 2016 Is there something wth htaccess ?
    How to hide Adsense ads for specific countries?
     
    lapidus, Oct 23, 2016 IP
  5. LilibethSantos

    LilibethSantos Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #5
    Here are a couple examples using .htaccess and php:
    http://stackoverflow.com/questions/9838344/how-to-redirect-domain-according-to-country-ip-address

    You can point your iframes or javascript code to your php script and it will sort out your traffic.
     
    LilibethSantos, Oct 23, 2016 IP
  6. lapidus

    lapidus Active Member

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #6
    Santos this is to block country,is not to block ads for specific country.
     
    lapidus, Oct 23, 2016 IP
  7. LilibethSantos

    LilibethSantos Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #7
    You can simply redirect the users from the undesired countries to a blank page or alternative ads. I don't really understand how it is unrelated.
     
    LilibethSantos, Oct 23, 2016 IP
  8. Einheijar

    Einheijar Well-Known Member

    Messages:
    498
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    115
    #8
    Users JP and ogah have already given the answer, just use an IP location database and some if statements to block ads for certain countries. I actually use statements like this quite often to display optimized ads based on location
     
    Einheijar, Oct 26, 2016 IP
  9. lapidus

    lapidus Active Member

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #9
    Thanks JP for this answer.Can you please just tell me do you have that script to i can implement in root folder or what is the best way to make that to work. I need a step by step guide how to do that because i am not familiar with those kind of things. Thanks
     
    lapidus, Oct 30, 2016 IP
  10. Einheijar

    Einheijar Well-Known Member

    Messages:
    498
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    115
    #10
    http://www.geoplugin.com/webservices/php

    You can use a free service.
    
    require_once('geoplugin.class.php');
    $geoplugin = new geoPlugin();
    // If we wanted to change the base currency, we would uncomment the following line
    // $geoplugin->currency = 'EUR';
    
    $geoplugin->locate();
    if ($geoplugin->countryCode == 'US' ) {
    //some adcode display
    }
    
    PHP:
    Repeat for whatever other countries you may have. You could also use a switch statement
     
    Einheijar, Oct 30, 2016 IP
  11. lapidus

    lapidus Active Member

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #11
    Thanks Einheijar

    Just tell me this code must go in root server folder for template or?
     
    lapidus, Nov 1, 2016 IP
  12. Einheijar

    Einheijar Well-Known Member

    Messages:
    498
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    115
    #12
    If your template can handle PHP then by all means download the php class and dump it in your template.
     
    Einheijar, Nov 1, 2016 IP
  13. lapidus

    lapidus Active Member

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #13
    Ok i have download php class and contain two files
    geoplugin.class.php and index.php

    Now in which file i can put some country code to hide adsense? Can you send me one example here for France code in example for test? To i can see how to do that. Thanks
     
    lapidus, Nov 4, 2016 IP