Allow Access To Folder Based On Referrer?

He has: 3 posts

Joined: Oct 2007

Hi everyone!

I'm trying to limit access to a folder on my hosted website to visitors from a certain page on my site.

In other words, I want to allow only visitors that are on mysite.com/members/content.php to be able to go from there to the mysite.com/downloads/ folder. Visitors from any other location, or visitors simply typing mysite.com/downloads (or a variation thereof) into their browser address bar should be denied access. Confused

I don't have root access, and if possible I want to do it using only a .htaccess file without the need for usernames and/or passwords (mysite/members/content.php is already a protected file).

Can anyone help?

Thanks,

Phil
Cool

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

As you are wanting to do this with just the .htaccess file (which it can be, I jsut don't recall ofhand the coding) I'm moving this to the more appropriate area on the forums.

On thing to not though, this is not completely reliable for two reasons, 1. you can fake this value, 2. some people browse with this blocked, weather they know it or not. I'm not sure if it still does, but at least for a while Norton Antivirus by default install would block this.

-Greg

He has: 629 posts

Joined: May 2007

A quick google confirms what Greg says - using .htaccess is unreliable. I suggest you set an identifying cookie with mysite.com/members/content.php - then test for that cookie in your mysite.com/downloads/ folder files. You will need a PHP file in that folder, of course, but having an index.php file there will prevent access to the directory listing (if it's not otherwise blocked).

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

He has: 3 posts

Joined: Oct 2007

Thanks Greg K and webwiz! Now let me confess something: Although I've been dabbling in web design for a number of years, I'm a total noob when it comes to either .htaccess files or cookies (I wouldn't recognize a cookie if it bit me on the butt!).

Could one of you point me in the right direction to learn about cookies - or better yet, just tell me (in some detail) how to solve my immediate problem? Wink

He has: 3 posts

Joined: Oct 2007

By the way, what happens if a visitor's browser has cookies turned off?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.