Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 6th, 2004, 10:44 AM
Rich's Avatar
Rich Rich is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Fort Lauderdale, FL
Posts: 152 Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 49 m 15 sec
Reputation Power: 22
How to Redirect users based on their IP Address

Very often we are confronted with a situation where we need to have different versions of the same site based on the country of origin of the user. There are many reasons for this. The content could differ in terms of registration forms or we might even have different language fonts for the regions. Another reason could be that you want to make a census as to how many people are coming from say INDIA or say from The WEST INDIES. What ever be the reason this arti ...

Very often we are confronted with a situation where we need to have different versions of the same site based on the country of origin of the user. There are many reasons for this.

The content could differ in terms of registration forms or we might even have different language fonts for the regions. Another reason could be that you want to make a census as to how many people are coming from say INDIA or say from The WEST INDIES. What ever be the reason this article helps you build a foundation on which to improvise.

It also comes with a Download version(zipped) of the coding. This article is meant to help create an asp program which will have the ability to redirect users based on their georaphical location. I have used a downloaded list of IPv4 ranges for india and written the code.



Here is a step-by-step approach to the problem...


Step 1 : Get the list of IPv4 ranges for the region of your choice(Look into www.apin.org for a beginning) and
extract the ip's into a text file say call it ip.txt.

Step 2 : Get the IP address of the user and split it into an array with "." as the delimiter

Step 3 : Load the IP addresses from up.txt into a 2 dimensional array

Step 4 : Now for each IP range split the starting ip and ending ip into two arrays

Step 5 : Compare the corresponding numbers of the user ip array with those of the fromip and toip arrays

Step 6 : Repeat Step 4 thru Step 5 in a while loop till u reach the end of the array.

Now Go thru the snippet of code below and readthru the comments to understand it line by line.<%
dim ipfromto(45,45)

yourip=split(request.ServerVariables("remote_addr"),".")


realpath=server.MapPath("./iponly.txt")


set myobj = server.CreateObject("scripting.filesystemobject")
set myfile = myobj.OpenTextFile(realpath)

i=1
while not myfile.atendofstream
line=myfile.readline
temp=split(line,"-")

ipfromto(i,1)=temp(0)
ipfromto(i,2)=temp(1)

i=i+1
wend
myfile.close


flag=false
j=1
While j< 46


'split the from-ip and to-ip based on "."
'fromip has the from ip address in four parts
'toip has the to ip address in four parts

fromip=split(ipfromto(j,1),".")
toip=split(ipfromto(j,2),".")
if yourip(0) > = fromip(0) and yourip(0) < = toip(0) then

if yourip(1) > = fromip(1) and yourip(1) < = toip(1) then

if yourip(2) > = fromip(2) and yourip(2) < = toip(2) then

if yourip(3) > = fromip(3) and yourip(3) < = toip(3) then

flag=true

end if

end if
end if

end if

if flag=true then
'Put your response.redirect() here
flag=false
else
'Put your response.redirect() here
end if

j=j+1
wend

%>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > How to Redirect users based on their IP Address


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek