Solved

stumped on referrer script

Posted on 2003-12-08
10
377 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
Comment Utility
<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
Comment Utility
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
Comment Utility
Loop what? Loop the error message?
0
 
LVL 15

Accepted Solution

by:
Timbo87 earned 140 total points
Comment Utility
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
Comment Utility
by looping i mean going nowhere .. keeping a blank page, ignoring all other script ... going nowhere

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:sanctify
Comment Utility
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
Comment Utility
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
Comment Utility
there now its at 1`40 instead of 85 !
0
 
LVL 1

Author Comment

by:sanctify
Comment Utility
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
Comment Utility
wait no .. i copied it wrong .. its working WOOOHOOOOO

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

771 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

11 Experts available now in Live!

Get 1:1 Help Now