Solved

stumped on referrer script

Posted on 2003-12-08
10
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
Timbo87 earned 140 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS (line height?) issue 2 78
Magento Indexing 1 132
CSS display:none AND display:block on same element 3 124
php mysql check email already in database. (second check) 7 146
When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 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