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 |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By Damodharan T.S. developerWorks - FREE Tools! | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
| | | | This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
| | | | Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
| | | | XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
| | | | Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
| | | | Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
| | | | You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |