Forum Moderators: open

Message Too Old, No Replies

Urgent Help Needed in Redirection

Urgent Help Needed in Redirection

         

lindajames

12:46 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



Hi, i am in urgent need of help in creating an asp script. I Will be very greatful if someone can help me out.

Basically i have the following script that detects a users IP, country and Country code from a .dat database.

<%
Option Explicit
%>
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode

Set 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
%>

<html>
<body>
IP: <%=strIP%> <br>
Country: <%=strCountryName%> <br>
Country Code: <%=strCountryCode%>
</body>
</html>

I want to to change the script so that depending on the country the user is from, instead of displaying their country name, i want the script to redirect the user to a page that is configured in the asp file.

So, basically if the user is from the following countries it should take them to the following pages:

United States = "usa/index.html"
United Kingdom = "uk/index.html"
France = "fr/index.html"
Default = "europe/index.html"

if the user is not from any of the 3 countries configured in the asp file, then the user should be taken to the Default page which is also configured in the asp file

I AM IN URGENT NEED TO GET THIS WORKING AND WOULD BE VERY GREATFUL IF SOMEONE CAN HELP ME OUT

I appreciate anyones help

Many Thanks
Linda

wardbekker

1:02 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



lindajames,

You can do it like this;

IF strCountryName = "United States" Then
Response.redirect("/usa/index.html")
END IF

etc

lindajames

1:19 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



thanx! how about if the country is anything other than the defined ones? i want to take them to the default url if the country is anything else?

thanx for ur help

really appreciate it.

cheers

Birdman

1:32 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IF strCountryName = "United States" Then
Response.redirect("usa/index.html")
IF strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
IF strCountryName = "France" Then
Response.redirect("fr/index.html")
Else
Response.redirect("europe/index.html")

END IF

lindajames

1:47 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



thanx for that! where shall i actually put that code? within the <html> tag? or at the top like this:

<%
Option Explicit
%>
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode

Set 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)

IF strCountryName = "United States" Then
Response.redirect("usa/index.html")
IF strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
IF strCountryName = "France" Then
Response.redirect("fr/index.html")
Else
Response.redirect("europe/index.html")

End If
Set oGeoIP = Nothing
%>

<html>
<body>
IP: <%=strIP%> <br>
Country: <%=strCountryName%> <br>
Country Code: <%=strCountryCode%>
</body>
</html>

Birdman

2:04 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could add it to the included file or put it at the very top of the page, above <html>.

lindajames

2:09 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



ive put it just above the <HTML> tag but im getting a HTTP 500 - Internal server error

what can be wrong?

this is how i put it:

<%
IF strCountryName = "United States" Then
Response.redirect("usa/index.html")
IF strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
IF strCountryName = "France" Then
Response.redirect("fr/index.html")
Else
Response.redirect("europe/index.html")
END IF
%>

<html>
<body>

</body>
</html>

Birdman

2:16 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this


<%
Option Explicit
%>
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode
Set 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)
IF strCountryName = "United States" Then
Response.redirect("usa/index.html")
IF strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
IF strCountryName = "France" Then
Response.redirect("fr/index.html")
Else
Response.redirect("europe/index.html")
END IF
End If
Set oGeoIP = Nothing
%>

aspdaddy

2:22 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would think a select..case is the way to go, or even better put the countries/pages into a map/dictionary whatever and then just use lookup syntax :

response.redirect myMap[ strCountryName ].value

lindajames

2:27 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



Birdman, I tried that code, but i am still getting HTTP 500 - Internal server error

any other suggestions?

Birdman

2:27 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was hoping you would come along and help, aspdaddy. I'm more accustomed to PHP, myself.

Is a Select similar to a switch() [php.net] statement?

aspdaddy

2:32 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, switch/select case is the same though I dont know the exact syntax in without my pocket vbScript :)

Pretty sure vbScript has some kinda map or dictionary object too.

lindajames

2:33 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



oh dear or dear :( now i am stuck :'(

Birdman

2:34 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the solution below to get a descriptive error message.


HTTP 500 - Internal server error
Internet Explorer

This problem occurs because there is an error processing the ASP script and "Friendly HTTP error messages" are enabled in Internet Explorer which do not allow you to see the details of the problem.

Solution(s):

In IE, turn off Friendly HTTP error messages by choosing tools - internet options - advanced. Then you should get the real error message and line number of the error.

lindajames

2:35 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



yes this is what i get:

Microsoft VBScript compilation error '800a03f6'

Expected 'End'

/index.asp, line 26

lindajames

2:49 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



well? any idea on what the problem is?

Birdman

3:08 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry Linda, I'm trying but I haven't used ASP in some time. Try this version where I added ElseIf. Also, do a search for "asp If Then" for an explanation of it's usage.

<%
Option Explicit
%>
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode
Set 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)
If strCountryName = "United States" Then
Response.redirect("usa/index.html")
ElseIf strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
ElseIf strCountryName = "France" Then
Response.redirect("fr/index.html")
Else
Response.redirect("europe/index.html")
End If
End If
Set oGeoIP = Nothing
%>

lindajames

3:12 pm on Mar 18, 2003 (gmt 0)

10+ Year Member



Hurray! it works now. :)

thanx alot. really appreciate it.

macrost

2:33 am on Mar 19, 2003 (gmt 0)

10+ Year Member



Try this.
[edit] Nevermind, was thinking about something else. [/edit]