PDA

View Full Version : Protecting a Page



legomind
08-24-2005, 09:37 PM
I am trying to protect a page from being accessed from any other page other than one. How can I do this?


I have tried This:


<script>
<!--

//specify valid referrals for script to accept
//if you wish an entire domain to be valid, enter that (ie: "google.com")
var validreferrals=new Array()
validreferrals[0]="my_page.htm"
validreferrals[1]="my_page.htm"

var passed=0

for (r=0;r<validreferrals.length;r++){
if (document.referrer.indexOf(validreferrals[r])!=-1){
passed=1
break
}
}

if (passed==0){
alert("Access to the page denied!")
history.go(-1)
}

//-->

</script>

But It Doen't Work!

Help! Anyone?

cr3ative
08-25-2005, 07:03 AM
You really want to do this server-side.

Add this to your .htaccess file and change as necessary :


# Prevent offsite links to download.htm
SetEnvIfNoCase Referer ^http://www\.your-domain\.com local
SetEnvIfNoCase Referer ^http://your-domain\.com local
SetEnvIf Referer ^$ local

<Files ~ "download\.htm$">
order deny,allow
deny from all
allow from env=local
</Files>

cr3

legomind
08-25-2005, 12:32 PM
I am new to this sort of thing. .htaccess? :confused:

Twey
08-25-2005, 01:05 PM
A file in the folder called .htaccess.

legomind
08-25-2005, 01:08 PM
I see, I make a foler named .htacces and put what type of file in it?

Twey
08-25-2005, 01:28 PM
No, you make a file called .htaccess in the folder with your files and put the above text in it. Although you might want to use ^download\.htm$ not download\.htm$.

legomind
08-25-2005, 01:32 PM
I can't use .htaccess with free web space!