redirect based on IP and referrer

T

Trev

Hi everyone,
I'm trying to modify an existing piece of Javascript that will enable a
redirect to a page based
on IP address and/or keywords in the referrer; for instance,
redirecting an existing member
to a page that bypasses introductory blurb etc. I've included the code
in an shtml file to allow
server side includes.

I've included the code below, but it doesn't work- it falls over at the
document.write("<META etc.
line, but I can't see why. Can anyone provide any clues?

Incidentally, would it be preferable to use use history.previous rather
than referrer?

Many thanks

Trev



<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
redirect(){
var ip = '<!--#echo var="REMOTE_ADDR"-->';

s = new String(document.referrer);

var teststring1="Whizz";
var teststring2="Bang";

// test IP and referrer strings
if (ip == "x.x.x.x" || ip == "x.x.x.x" || ( s.test(teststring1) &&
s.test(teststring2))) {

document.write('<META HTTP-EQUIV="Refresh"
CONTENT="0;URL=http://www.otherpage/members.html">');


}
}
redirect();
// End -->
</script>

</HEAD>

<!-- default page content here-->
 
T

Trev

I've slimmed down the code to the following, which I think is causing
the problems, but it is still causing me grief :(
It should redirect if the referring page contains WhizzBang in the URL

Can anyone suggest what is wrong - it doesn't even display the dialog
box!

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
redirect()
{

var s = document.referrer;

alert('1: Your referrer is '+s);

var teststring1="Whizz";
var teststring2="Bang";

// test referrer strings
if ( s.test(teststring1) && s.test(teststring2))
{

document.write('<META HTTP-EQUIV="Refresh"
CONTENT="0;URL=404.htm">');

}
}

redirect();
// End -->
</script>

</HEAD>

<BODY>
You should never see this....
</BODY>

</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top