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

simple regular expression problem with document.referrer

P: n/a
I have to determine the document.referrer of the individual coming to my
site. I want to send everyone not coming from one of those sites to an
alternate location (The names below are just used as examples).
I want to match on one of those names anywhere in the document.referrer.

In the main program I call a subroutine like this:
<script LANGUAGE="javascript" SRC="../js/redirect.js"></script>
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0"
onload="checksource()">

inside redirect.js subroutine:
function checksource() {
if(document.referrer !~ /(equifax|transunion|experian)/) {
alert("\n\nThis function may only be accessed from a member
angency.\n\nPlease click OK to be redirected to the appropriate page.\n\n");
location.href = "http://999.999.999.999/bad_source.asp";
}
}

However, everytime this code is executed, it generates a runtime
error:error:
line:2
Error:Expected ')'
I have researched this and it seems identical to some examples I have seen.
What am I missing?
Is there a better way to do this?
Thanks for your help!
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Goober wrote:
I have to determine the document.referrer of the individual coming to my
site. I want to send everyone not coming from one of those sites to an
alternate location (The names below are just used as examples).
I want to match on one of those names anywhere in the document.referrer.

In the main program I call a subroutine like this:
<script LANGUAGE="javascript" SRC="../js/redirect.js"></script>
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0"
onload="checksource()">

inside redirect.js subroutine:
function checksource() {
if(document.referrer !~ /(equifax|transunion|experian)/) {
if (!/(equifax|transunion|experian)/.test(document.referrer)) {

will do the trick, however I suspect you have a much larger range of
values to check and there are other issues with what you are trying
to do...

[...]
I have researched this and it seems identical to some examples I have seen.
What am I missing?
This is a server-side issue but you appear to be using what is
primarily a client-side technology. Are you sure you're there isn't
something better?
Is there a better way to do this?
Most probably, but the real issue is your expectation that
document.referrer is reliable - it absolutely isn't. It is very
easily spoofed and can't be relied up at all.
Thanks for your help!


I hope I did.
--
Rob
Jul 23 '05 #2

P: n/a

"RobG" <rg***@iinet.net.auau> wrote in message
news:Za****************@news.optus.net.au...
Goober wrote:
I have to determine the document.referrer of the individual coming to my
site. I want to send everyone not coming from one of those sites to an
alternate location (The names below are just used as examples).
I want to match on one of those names anywhere in the document.referrer.

In the main program I call a subroutine like this:
<script LANGUAGE="javascript" SRC="../js/redirect.js"></script>
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0"
onload="checksource()">

inside redirect.js subroutine:
function checksource() {
if(document.referrer !~ /(equifax|transunion|experian)/) {


if (!/(equifax|transunion|experian)/.test(document.referrer)) {

will do the trick, however I suspect you have a much larger range of
values to check and there are other issues with what you are trying
to do...

[...]

I have researched this and it seems identical to some examples I have
seen.
What am I missing?


This is a server-side issue but you appear to be using what is
primarily a client-side technology. Are you sure you're there isn't
something better?
Is there a better way to do this?


Most probably, but the real issue is your expectation that
document.referrer is reliable - it absolutely isn't. It is very
easily spoofed and can't be relied up at all.
Thanks for your help!


I hope I did.
--
Rob

You did help. Thank you much.
By the way, this is not meant as high security. Just a marketing thing where
they want to control flow. If security was a concern, I would explore
something different.
Again,Thanks
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.