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! | Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
| | | | This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
| | | | Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
| | | | IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
| | | | Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
| | | | In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
| | | | User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
| | | | The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |