Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

stumped on referrer script

Posted on 2003-12-08
10
Medium Priority
?
385 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 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