Page 1 of 1

Password Protect a file/folder

Posted: Thu Feb 10, 2011 8:50 am
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

Re: Password Protect a file/folder

Posted: Thu Feb 10, 2011 9:04 am
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

Re: Password Protect a file/folder

Posted: Thu Feb 10, 2011 9:18 am
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.

Re: Password Protect a file/folder

Posted: Thu Feb 10, 2011 10:07 am
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.

Re: Password Protect a file/folder

Posted: Thu Feb 10, 2011 10:39 am
by computerikon
Thanks John, I will look into that.