Solved

Referrer check to restrict direct file access - javascript

Posted on 2009-04-03
3
489 Views
Last Modified: 2012-06-22
I need a simple javascript I can put in the top of my HTML page to check the referrer, and show/hide the page.  I know this isn't the most secure resolution, but I only need it as a temp solution.

For example, I only want to allow access from two domains (domain1.com and domain2.com).  

Site users will be coming from inside an application to this static HTML page, so the referrer will be correct and will allow it to be viewed.  I want to DISSALLOW access by direct URL, which would lack the correct referrer.

I can't post any page code due to NDA  :(

Thanks for your help!
0
Comment
Question by:northlandadv
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
<script>
if (document.referrer.indexOf('domain1') == -1 and document.referrer.indexOf('domain2') == -1) {
  document.write('<style>* { display:none }</style>')
}
</script>

or

<script>
if (document.referrer.indexOf('domain1') == -1 and document.referrer.indexOf('domain2') == -1) {
   location.replace('goaway.html')
 }
 </script>
 
0
 

Author Comment

by:northlandadv
Comment Utility
Hey Thanks!  I'll give it a shot..
0
 

Accepted Solution

by:
northlandadv earned 0 total points
Comment Utility
I was never able to get this to work  :(   I ended up just using the htacess in the end, since it was less hassle.  Thanks anyway.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

728 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

8 Experts available now in Live!

Get 1:1 Help Now