Solved

stumped on referrer script

Posted on 2003-12-08
10
378 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
css help 3 110
recommended CMS for the website revamp 3 92
Format results with PHP 3 68
Getting dynamic value from 3rd party page and passing to a function on another page 1 92
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now