Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

stumped on referrer script

Posted on 2003-12-08
10
Medium Priority
?
386 Views
Last Modified: 2012-05-04
i am trying to get a script that will work accross all major browsers, that will limit access to pages by referring page.

specifically, one that will not load if the referring page is null or opened in a browser (no referrer), and that wont open if they dont come from a page i specify ....  maybe with a popup message for error and something like that

maybe even having a cookie from the referring page checked by the script access page, in case the referring page idea isnt completely foolproof .

ect


things along those lines ... jsut trying to secure my domain =)


thanks =)
0
Comment
Question by:sanctify
  • 7
  • 3
10 Comments
 
LVL 15

Expert Comment

by:Timbo87
ID: 9899609
<script langauge="JavaScript" type="text/javascript">
if(document.referrer != "http://www.yoursite.com")
{
      alert("You do not have access to this page.")
      parent.window.location = "http://www.google.com"
}
</script>

This script will check if you came from a specific URL, if not it will popup and error message and redirect you.

Change http://www.yoursite.com to the only site that the user can view the page from. Change http://www.google.com to the page you want to redirect to if they don't come from the proper URL.
0
 
LVL 1

Author Comment

by:sanctify
ID: 9899890
ok ..what if there are multiple pages a user can come from ????

instead of redirecting is there a way to jsut loop it so they go nowhere  ?  
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9900005
Loop what? Loop the error message?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Accepted Solution

by:
Timbo87 earned 560 total points
ID: 9900052
Here's a modified version that allows multiple URLs:

<script langauge="JavaScript" type="text/javascript">
var allowed = false
var validURL = new Array()

validURL[0] = "http://www.yahoo.com"
validURL[1] = "http://www.google.com"
validURL[2] = "http://www.cnn.com"

for(i=0;i<validURL.length;i++)
{
      if(document.referrer == validURL[i])
      allowed = true
}

if(!allowed)
{
      alert("You do not have access to this page.")
      window.location = "http://www.google.com"
}
</script>

You can add as many validURL's as you want:
validURL[3] = "http://www.cnet.com"
validURL[4] = "http://www.microsoft.com"

If the referrer is not in the validURL array, it will display an error.
0
 
LVL 1

Author Comment

by:sanctify
ID: 9903502
by looping i mean going nowhere .. keeping a blank page, ignoring all other script ... going nowhere

0
 
LVL 1

Author Comment

by:sanctify
ID: 9903511
or wait ... looping the script would be good ..then if they access it they would ahve to  delete the iexplorer.exe from the task manager to get out of it .... how do i do that ?

by the way ..thank you !!!!!!!!!!!!!!!!!!!!!!
0
 
LVL 1

Author Comment

by:sanctify
ID: 9903515
maybe i could have a few options of both to use ... ill increase the points ...hold on ...thanks again ... you are teaching me alot !!!!!!!!!
0
 
LVL 1

Author Comment

by:sanctify
ID: 9903519
there now its at 1`40 instead of 85 !
0
 
LVL 1

Author Comment

by:sanctify
ID: 9903688
the script u gave me isnt working ...

it gives me the error even if im coming from the valid page ...thank you !
0
 
LVL 1

Author Comment

by:sanctify
ID: 9904235
wait no .. i copied it wrong .. its working WOOOHOOOOO

THANKS !!!!!!!!!!!!!!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question