1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I hide Adsense for Wikipedia visitors?

Discussion in 'PHP & Perl' started by UnDerDoG81, Nov 7, 2013.

  1. UnDerDoG81

    UnDerDoG81 Regular Member

    Joined:
    Oct 29, 2009
    Messages:
    370
    Likes Received:
    68
    Hi,

    I´m a noob in php and want to know how to hide Adsense ads from Wikipedia visitors? And how can I implement this in Wordpress?

    All I´ve found out till now is this short code:

    PHP:
    $_SERVER['HTTP_REFERER']
    Would be great if anybody can help me with this?
     
  2. bytzu

    bytzu Registered Member

    Joined:
    Jun 30, 2011
    Messages:
    96
    Likes Received:
    137
    To get the referer and see if your traffic comes from Wikipedia you can use this code:

    Code:
    $is_from_wikipedia = '';
    if(isset($_SERVER['HTTP_REFERER'])) {
        $referar = $_SERVER['HTTP_REFERER'];
        if($referar!=''){
            $find_wikipedia = strpos($referar, 'wikipedia.org');
            if($find_wikipedia!==false){
                $is_from_wikipedia = '1';
            }
        }
    }
    
    
    if($is_from_wikipedia==''){
        // your adsense code goes here
    }
    I didn't have time to test my code but it probably works. If i am not wrong this will work only for the first page the user land on.

    To be more clear i'll give you an example. The user comes form wikipedia to page_a.html having the referal wikipedia. But if he navigates to another page inside your site let's say page_b.html the referer will now become page_a.html. In this case the ads will be shown. If you do not want this PM me and i will help you with the code.

    In order to put it inside your wordpress site varies depending on how you load the adsense ads (with the help of a extesion, directly in the template)
     
    • Thanks Thanks x 1
  3. UnDerDoG81

    UnDerDoG81 Regular Member

    Joined:
    Oct 29, 2009
    Messages:
    370
    Likes Received:
    68
    Thank you very very much sir!