Link to home
Start Free TrialLog in
Avatar of mpopal
mpopalFlag for United States of America

asked on

How to redirect based on IP address

How do I redirect visitors to a web site by their source IP address. I want to be able to send users local to the network to one web page, and anyone outside of the company to a different web page.

I want to send the local IP address range of 10.0.0.1 through 10.0.254.254 to index1.asp
and
I wan to sent all others to index2.asp.

I've found some sample asp code from google, but I haven't had any success yet.

Thanks.
Avatar of suramsureshbabu
suramsureshbabu

Use CGI variable REMOTE_ADDRESS to find out the IP address of the visitor and redirect based on it.
Sorry, the correct variable name is REMOTE_ADDR
Avatar of mpopal

ASKER

suramsureshbabu, I found the same site when I did a google search, but I'm not a programmer so that site doesn't help me out. There are a lot of fill in the blanks which I really have no clue what I need to replace with.

 RanjeetRain, I'll have to search for the CGI script, but again, I'm not a programmer or even web developer, so it doesn't mean a lot when I look at script.

What I was hoping was someone could create a few lines of code for me with the IP address that I listed and then I can copy the code into an asp or html file.

Thanks.
try somthing like this?

If instr(1, Request.ServerVariables("REMOTE_HOST"), "192.") Then '--this is a local user
response.Redirect("local.asp")
Else
response.Redirect("http://other.com")
End If

../mk
ASKER CERTIFIED SOLUTION
Avatar of seb_gibbs
seb_gibbs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mpopal

ASKER

seb gibbs, it worked perfectly after I added <% and %>

Thanks!!!
Yes you can redirect by requesting the "REMORE_ADDR" but you have to know that let's say 10 users are behind a firewall that they may all return the same IP address.

Regards
Dimitris
seb_gibbs or anyone, I am not a programmer but need this exact functionality for our Intranet web page.  How do I code I use this code in a web page.  Basically I did this:

<HTML>
<HEAD>
<%
remoteIP = request.servervariables("REMOTE_ADDR")
If left(remoteIP,5)="192.168." then page="index1.htm" else page="index2.htm"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", page
%>
<TITLE> Test </TITLE>
</HEAD>
<body>
</BODY>
</HTML>

and that doesn't work.  Any hints?


Lee
<%
       Dim strRemoteIP
       Dim strParsedIP
       Dim strRedirectPageName
       Dim strDesiredIPRange

        strRemoteIP = request.servervariables("REMOTE_ADDR")

        'THIS WILL GRAB THE 8 LEFT-MOST CHARACTERS
        strParsedIP = Left(strRemoteIP, 8)

        strDesiredIPRange = "192.168."

        If strParsedIP =  strDesiredIPRange Then
            strRedirectPageName = "index1.htm"
        Else
            strRedirectPageName = "index2.htm"
        End If

        Response.Redirect(strRedirectPageName)
%>