GoGreen PC Tune-Up™
Learn More

Insta-Install™
this is how ssl encrypt our websites
MTNCOMP | List View | Table View | myBlog (1867 Entries)
myBlog Home

Blog


IP-API.com examples and usage for Geo-Fending and Geo-Location and HREFLANG

by Mountain Computers Inc, Publication Date: Saturday, August 1, 2026

View Count: 71, Keywords: Geo-Location, IP-API, Geo-Fencing, Hashtags: #Geo-Location #IP-API #Geo-Fencing



IP-API.com is a fascinating service that I started using about 6 months ago. Again, its fascinating.
 
How do you use it? Well, consider your website is US only, and you want to keep out the rest of the world? What if your customer is French only, and you want France only customers?
 
My example that I use in a header file of my websites is the following since I have HREFLANG in play for translating my website content automatically in advance, and if not, then a 404 is used with a polite message.
 
in one header include file I have the following function
  
Function GetCountryCode()
    Dim ip, http, json, startPos, endPos, code

    ' Get client IP
    ip = Request.ServerVariables("HTTP_CF_CONNECTING_IP")
    If ip = "" Then ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If ip = "" Then ip = Request.ServerVariables("REMOTE_ADDR")

    ' Query simple free geo API
    Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
    'http.Open "GET", "http://ip-api.com/json/" & ip & "?fields=countryCode", False
    http.Open "GET", "https://pro.ip-api.com/json/" & ip & "?key=ONE-OF-YOUR-API-KEYS", False
    http.Send
    json = http.ResponseText
    Set http = Nothing

    ' Extract the "countryCode" value from JSON
    startPos = InStr(json, """countryCode"":""")
    If startPos > 0 Then
        startPos = startPos + 15
        endPos = InStr(startPos, json, """")
        code = Mid(json, startPos, endPos - startPos)
    Else
        code = ""
    End If

    GetCountryCode = code
End Function
 
in the next header include file i have the following
 
dim country_code, ip
ip = Request.ServerVariables("HTTP_CF_CONNECTING_IP")
If ip = "" Then ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ip = "" Then ip = Request.ServerVariables("REMOTE_ADDR")

country_code = GetCountryCode()
if country_code = "US" then 
else
    response.redirect "/404.asp?msg=Unable-To-Access-HREFLANG-" & country_code & "-in-Maintenance-Mode&ip=" & ip
end if
 

' Example usage:
' Response.Write "Country Code: " & GetCountryCode() 
 
 
IP-API can do that. Get the Professional Subscription and enjoy. I did. 
 
more to come...
  
REF: https://ip-api.com/
 

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2026 myBlog™ v1.2 All rights reserved. We count views as reads, so let's not over think it.