Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change link on guest IP address

Status
Not open for further replies.

apeoortje

Technical User
May 26, 2004
46
NL
I'm trying to write a script that depending on theier IP address the link will change to a different website.

I only normaly wirte in VBA, so as you can guess the code below doesn't work!!! any ideas on what I'm doing wrong?!?

<HTML>
<HEAD>

<TITLE></TITLE>

<SCRIPT LANGUAGE="JavaScript">
function ChangePage(){

UserIP = Request.ServerVariables("Remote_Addr")

if ("UserIP" = '1.1.1.1')
document.location =' else
document.location ='}
</script>
</head>

<BODY>

<P>Go to ;</P>
<a href="javascript:ChangePage();">Test</a>

</BODY>
</HTML>
 
I'm not sure if you can get the IP address at all in Javascript, but Request.ServerVariables("Remote_Addr") doesn't work.

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Thanks, do you know if there is somewhere, where I can find out if it's possable?!?
 
I doubt it is possible. You would need an asp (or php, etc) page something like this (I'm not good at ASP though...):
Code:
<% @Language=VBScript %>
<html>
<head>
<title>IP Address<title>
<SCRIPT LANGUAGE="JavaScript">
function ChangePage(){

UserIP = [red]<%=Request.ServerVariables("Remote_Addr") %>[/red]

    if ("UserIP" = '1.1.1.1')
    document.location ='[URL unfurl="true"]http://www.yahoo.com';[/URL]
    else
    document.location ='[URL unfurl="true"]http://www.msn.com';[/URL]
}
</script>
</head>

<BODY>

<P>Go to ;</P>
<a href="javascript:ChangePage();">Test</a>

</BODY>
</HTML>

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
If this is an ASP page you need to wrap that bit of code in the ASP delimiters:

Code:
function ChangePage(){
  UserIP = '<%=Request.ServerVariables("Remote_Addr")%>'

  if (UserIP = '1.1.1.1')
    location.href = '[URL unfurl="true"]http://www.yahoo.com';[/URL]
  else
    location.href = '[URL unfurl="true"]http://www.msn.com';[/URL]
}

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top