By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

redirect based on IP and referrer

P: n/a
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-->

Oct 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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>

Oct 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.