Password Protect a file/folder

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
computerikon
Forum Newbie
Posts: 3
Joined: Thu Feb 10, 2011 8:46 am

Password Protect a file/folder

Post by computerikon »

I'm new to this forum and to PHP, please bear with me...

I have this PHP login script where the user logs in and is able to view protected pages. When I create a separate folder at mydomain.net/videos that I want to password protect so that only a registered user who are logged in can access the video content within that folder. But I know you could just go directly to mydomain.net/videos and go around the login script and access the files without being logged in. Suggestion or help is much appreciated

The script that I am using is from http://php-login-script.com
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Password Protect a file/folder

Post by John Cartwright »

The safest way to do this is put all your videos beneath the document root, and serve your video's through a php script which checks if they are authenticated, and if they are, serve the file through readfile() + appropriate header()'s
computerikon
Forum Newbie
Posts: 3
Joined: Thu Feb 10, 2011 8:46 am

Re: Password Protect a file/folder

Post by computerikon »

Thanks for the reply John,

Would you know where I could find such a script at? Or something that i could work off of. I have been learning web code all on my own, so it has been a rough ride so far.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Password Protect a file/folder

Post by John Cartwright »

I don't know of any scripts... take a look at readfile(), which has a ton of good examples on using it to serve as a download script.
computerikon
Forum Newbie
Posts: 3
Joined: Thu Feb 10, 2011 8:46 am

Re: Password Protect a file/folder

Post by computerikon »

Thanks John, I will look into that.
Post Reply