How To Show Custom Ads To only US visitors?

Discussion in 'Programming' started by dark0circles, Oct 29, 2007.

  1. #1
    Hi,

    I would like to show my own custom ads/links to only visitors from US. Can I know how can I do this? Thanks you.
     
    dark0circles, Oct 29, 2007 IP
  2. iwyrobi

    iwyrobi Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to know the ip address of your visitor, and list of us ip address. then just check the ip, if non us don't display the ads.

    hope this help you.
     
    iwyrobi, Oct 29, 2007 IP
  3. dark0circles

    dark0circles Peon

    Messages:
    660
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is there any general code to do that?
     
    dark0circles, Oct 29, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It is very easy to do but you either need to buy a database of IPs or subscribe to a geolocator web service - remember that the IPs change over time so even if you buy the data you have to "budget" for updating the database a couple of times a year.

    A very simple example in .Net using an adrotator to control the showing of adverts would be:

    
    '''' get users country from IP
            Dim sqlquery As String = "SELECT country FROM iptocountry WHERE ip = @ip"
            Dim sqlconn As New SqlConnection("your connectionstring")
            Dim sqlcomm As New SqlCommand(sqlquery, sqlconn)
            Dim country As String
            sqlcomm.Parameters.AddWithValue("ip", Request.UserHostAddress)
            sqlconn.Open()
            country = sqlcomm.ExecuteScalar
            sqlconn.Close()
            
    '''' Logic on ad filtering
            If country = "USA" Then
                AdRotator1.KeywordFilter = "USA"
            Else
                AdRotator1.KeywordFilter = "Non-USA"
            End If
    
    Code (.Net):
     
    AstarothSolutions, Oct 30, 2007 IP