Find Visitor Geographical Location from IP Address Using ASP

xiaoxiao2021-03-06  39

Find Visitor Geographical Location from IP Address Using ASP

http://www.codetoad.com/asp_geoip.asp

Download Geoip Files - 6 KB

Online Demo

Introduction

With GeoIP you can detect where your visitors are coming from. You can use this information to deliver personalized information (see image below), reducing credit card fraud, analyzing web server logs (I use it for SNIFF), target banner ads, .. .. (See Solutions At Maxmind -

http://www.maxmind.com/)

Click on The Image for A Test

Note

If you can install a Component On your Web Server, you would donload the geoip component from maxMind. I Wrote GeoIP.asp Since My Provider Doesn't Allow Me To Install Components.

Prerequisite

You need the geoip database -

Http://www.maxmind.com/app/free, and you need ado 2.5 or later since geoip.asp Uses the ado stream object to read the geoip database.

Installation

Download The Geoip.dat Database from Maxmind

Http://www.maxmind.com/app/free Put Geoip.asp, Example.asp and Geoip.dat in a catalog on your web server. Test the installation by accessing the example.asp page http: // yourserver / path /EXAMPLE.ASP

Methods and Properties

Geoip.asp Exposes these Public Methods and Properties

Properties:

GeoipDatabase - Sets the path and filename to geoip.dat errnum - returns the error Number (if <> 0, there is an error)

Methods:

LookupCountryName - Find AN IP's Country Name Example:

STRCOUNTRYNAME = OGEOIP.LOOKUPCOUNTRYNAME (Strip)

LookupCountryCode - Find An IP's Country Code Example:

STRCOUNTRYCODE = OGEOIP.LOOKUPCOUNTRYCODE (STRIP)

USING THE CODE

It's Rather Simple To Use this code:

Select all code

<%

Dim Ogeoip, Strerrmsg

DIM Strip, StrcountryName, StrCountryCodeEt Ogeoip = New Countrylookup

Ogeoip.geoipdatabase = server.mappath ("geoip.dat")

IF Ogeoip.errnum (STRERRMSG) <> 0 THEN

Response.write (STRERRMSG)

Else

Strip = Request.serverVariables ("remote_addr")

STRCOUNTRYNAME = OGEOIP.LOOKUPCOUNTRYNAME (Strip)

STRCOUNTRYCODE = OGEOIP.LOOKUPCOUNTRYCODE (STRIP)

END IF

Set Ogeoip = Nothing

%>

转载请注明原文地址:https://www.9cbs.com/read-58342.html

New Post(0)