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.

tutorial or howto for geo targeting the ads?

Discussion in 'Publisher Network' started by jeremy860, Feb 2, 2006.

  1. #1
    Hi,
    SEMrush
    I was just wondering if anyone knows of a simple tutorial for displaying YPN ads to usa visitors and adsense ads to international visitors? Is there a script a guy could get?
     
    jeremy860, Feb 2, 2006 IP
    SEMrush
  2. ServerUnion

    ServerUnion Peon

    Messages:
    3,615
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here is a simple way to do it. Is fairly accurate.

    <?PHP
    $ip = $_SERVER[REMOTE_ADDR];
    $ip = gethostbyaddr($ip);
    $ip = substr($ip,(strlen($ip)-3),strlen($ip));
    if ($ip == "com") {
     echo("in america");
    }
    else {
     echo("you are a forign dueche");
    }
    
    
    ?>
    Code (markup):
     
    ServerUnion, Feb 2, 2006 IP
  3. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #3
    are you serious or just messin with me, that code looks like it would be something that would block ALL traffic or something
     
    jeremy860, Feb 2, 2006 IP
  4. ServerUnion

    ServerUnion Peon

    Messages:
    3,615
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That will tell you if someone is domestic to the US or foriegn. The implamentation is up to you. Good luck...
     
    ServerUnion, Feb 2, 2006 IP
  5. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #5
    ok thats cool , but could you display what this code is actually doing and how it is determining if the person is from the usa or not?


    $ip = $_SERVER[REMOTE_ADDR];
    $ip = gethostbyaddr($ip);
    $ip = substr($ip,(strlen($ip)-3),strlen($ip));
    if ($ip == "com") {
    Code (markup):
     
    jeremy860, Feb 2, 2006 IP
  6. ServerUnion

    ServerUnion Peon

    Messages:
    3,615
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    0
    #6
    its not terribly accurate but it does work.
     
    ServerUnion, Feb 2, 2006 IP
  7. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #7
    alright well i'll give it a shot
     
    jeremy860, Feb 2, 2006 IP
  8. keikor

    keikor Peon

    Messages:
    665
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hmm jeremy, is that code working? I would like to try out also?
     
    keikor, Feb 2, 2006 IP
  9. bluegill_catcher

    bluegill_catcher Active Member

    Messages:
    862
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    58
    #9
    My ISP and host that I have used for almost 10 years does not offer PHP or MySql support. Any other ways to show non usa visitors Adsense ads instead of YPN ? javascript ?
     
    bluegill_catcher, Feb 3, 2006 IP
  10. Tranix

    Tranix Peon

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Insert this code in the header page or wherelse?

    Thanks in advance,
    Tranix ;)
     
    Tranix, Feb 3, 2006 IP
  11. keikor

    keikor Peon

    Messages:
    665
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hey tranix, that asian chick in your avatar is damn hot.

    Who's she? :)
     
    keikor, Feb 3, 2006 IP
  12. mustangsally

    mustangsally Peon

    Messages:
    436
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #12
    
    <?PHP
    $ip = $_SERVER[REMOTE_ADDR];
    $ip = gethostbyaddr($ip);
    $ip = substr($ip,(strlen($ip)-3),strlen($ip));
    if ($ip == "com") {
     echo("YOUR YPN CODE HERE");
    }
    else {
     echo("YOUR ADSENSE CODE HERE");
    }
    
    
    ?>
    
    Code (markup):
    Just put that where your ads would be
     
    mustangsally, Feb 3, 2006 IP
  13. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #13
    Hey, have a look here:
    http://www.maxmind.com/app/geoip_country

    They offer a free (GPL) ip2country database and also some scripting help. I'm using it and works great!! You just have to put your ads in a switch-case depending on the country code (which is easily obtained - have a look at their files! Details on their php module here: http://www.maxmind.com/app/php )

    Hope this helps
     
    mihaidamianov, Feb 3, 2006 IP
  14. keikor

    keikor Peon

    Messages:
    665
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Has anybody got this working? I have no idea what the code means. What does "com" do?

    And how do i test the accuracy of this? Do i tell my foreign friends to help me check the ads? Or do i go proxy site to do it?

    ANybody knows of any proxy site where they offer foreign ip or something?
     
    keikor, Feb 3, 2006 IP
  15. thame

    thame Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I currently have my geotargetting set up through PHPAdsNew, but it's a little too much for my needs.

    If anyone has a simpler geotargetting script (one that connects to an IP database and not a simple host filter) please post here if you're comfortable doing so or email me at &#116;&#111;&#109;&#102;&#97;&#100;&#105;&#97;&#108;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;
     
    thame, Feb 3, 2006 IP
  16. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #16
    ^ yea no kidding, phpadsnew is way too heavy
     
    jeremy860, Feb 3, 2006 IP
  17. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #17
    <?
    include("geoip.inc");
    
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
    
    $visitor_country_code=geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    $visitor_country_name=geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    
    ?> 
    PHP:
    In order for this to work, you need to get these files:
    - GeoIP.dat from http://www.maxmind.com/app/geoip_country
    - geoip.inc from http://www.maxmind.com/download/geoip/api/php/

    You can use $visitor_country_code and $visitor_country_name to target your ads country specific. I'll be working on a script for this, 'cause phpadsnew is way too complex for just doing that.
    I hope this time you took the time to read the post, it's all written above as well.
     
    mihaidamianov, Feb 4, 2006 IP
  18. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #18
    Thank you for that^ But where would we put the adsense and ypn codes at?
     
    jeremy860, Feb 4, 2006 IP
  19. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #19
    Ufff... After you've done all of the above you can use - let's say - $visitor_country_code this way:

    <?
    switch ($visitor_country_code) {
    case "AU": {  
      switch ($vrand=rand(1,2)) {
        case 1: {
             //1st banner for Australian visitors
    
         ?> HTML CODE FOR ADSENSE OR WHATEVER <?
    
       }
       break;
       case 2: {
           //2nd banner for Australian visitors
       }
       break;
     }
     break;
    case "RO": {
       //banner for Romanian visitors
      }
      break;
    default: { // any country not mentioned
      }
    }
    ?>
    Code (markup):
    When you put the banner codes, don't forget to close php "?>" and open it "<?" after the HTML code
    I hope that is clear. The above script is not copy/pasted (not verified) so I hope all syntaxes are ok :) . If you have troubles, post the error here
     
    mihaidamianov, Feb 4, 2006 IP
  20. jeremy860

    jeremy860 Well-Known Member

    Messages:
    935
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #20
    ok so this would be the exact code to display YPN ads to all usa visitors and adsense ads to all people in other countries? thats how I would like to have it set up if possible
     
    jeremy860, Feb 4, 2006 IP