![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
Ok so I've done a lot of searching on the web and i've decided to post here as I cannot find a solution to my problem.
Getting php login authentication information passed on to, and verified by, .htaccess protected directories... What I want:
Here's what I have so far:
Here's my problem: I cannot get the two systems to work together. What I want ideally is to have the user login within the login page, and be able to access the content in the .htaccess protected directories without the .htaccess window poping up. In essence I want the user authentication to be gathered in the login page to be passed on to the .htaccess prompt so that it doesn't open and automatically authenticates and allows an authenticated user to access the material. Is this even possible? Because both the php and .htaccess authentication systems are now set up to verify username and password combinations against a mysql database, then shouldn't it be possible to have the data from the login screen passed on to the .htaccess authentication? The reason I'm using this method is because I want my video files protected, and the only way I've been able to do that (preventing direct linking to files) is through the use of .htaccess, which I've set up to use the mysql database instead of the annoying, cumbersome, and less secure .htpasswd file. Thank you very much! Any help would be greatly appriciated! Last edited by mwgriffin; 05-22-2009 at 02:06 AM.. |
|
|
|
|
|
PM User | #2 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
Ok so I found something that might help. I heard that you could store session information in a mysql database. If so, could the .htaccess file be directed to look in the mysql database for the session information? this would fix the issue, if it is possible, as the initial login would store the session information in the mysql database, the .htaccess file would then check the database for session information instead of what it normally does, then if there was no session active it would show the popup box, prompting the user to login. Possible???? Thanks!
|
|
|
|
|
|
PM User | #3 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
Ok so I'm going to rephase what I want, simply as this:
How do I protect files (picutes videos zipped archives) from unauthenticated users viewing or downloading them? I need a security system that stops someone that has a direct link to a file from downloading it or viewing it unless they're authenticated. .htaccess files would work great but I'm having some issues setting them up with a database for password and username reference. That and the fact that I need to have the php sessions be used for the .htaccess files, so that a logged in user isn't prompted by a popup window asking for login information again when accessing a file in a protected directory. Any suggestions? |
|
|
|
|
|
PM User | #4 |
|
Regular Coder ![]() Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 28 Times in 27 Posts
![]() |
Place an .htaccess file in www.domain.com/downloads, and put this in it:
<files *> Deny from all </files>
__________________
Unlimit the Impossible
DO NOT CLICK ON THIS LINK!!!!! ||AWESOME Flash Stuff|||Good Flash Stuff|||Good PSD Files|| Sea4Me |
|
|
|
|
|
PM User | #5 | ||
|
Moderator ![]() ![]() Join Date: Mar 2007
Location: Florida, USA
Posts: 2,529
Thanks: 1
Thanked 222 Times in 215 Posts
![]() ![]() |
Quote:
Quote:
|
||
|
|
|
|
|
PM User | #6 |
|
Regular Coder ![]() Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 28 Times in 27 Posts
![]() |
ya, put them in a downloads folder and use the server to access it... that way the guy can't download it but the server can still get it...
__________________
Unlimit the Impossible
DO NOT CLICK ON THIS LINK!!!!! ||AWESOME Flash Stuff|||Good Flash Stuff|||Good PSD Files|| Sea4Me |
|
|
|
|
|
PM User | #7 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
Hey thanks for the info! sea4me, if i'm understanding you correctly, I can use php to serve those files out of that directory? If that will block all access to that folder period then it is of no use to me as I want authenticated members to be able to access that material in the folder... I find it odd how it is so difficult to set something like this up. How do commercial sites do it? I know that with many of them you must be authenticated to download material, and you cannot download the material even if you have the referer information. I really wish there was someway you could secure folders like you secure individual pages with php. Is there an option to put the files above the web root and then serve them from that location with php that only works when the user is logged in. That to me sounds feasible. Is that a possible way of doing it?
|
|
|
|
|
|
PM User | #8 |
|
Senior Coder ![]() Join Date: Aug 2006
Location: Southampton
Posts: 1,281
Thanks: 58
Thanked 94 Times in 93 Posts
![]() |
Yeah that is how you do it with SESSIONS and HEADERS. You can use the download directory either above the doc root or deny all access with htaccess as shown above. Here is some example code:
PHP Code:
if ($handle = opendir('/direcotry/with/files')) so that the string in here is the path to your files. Then to get the relevant file you just calldownload.php?file=filename.mp3 where download would be the name of this script file. However you must ensure that filename.mp3 is urlencoded for this to work and that your sessions set $_SESSION["logged"]=1; when the user logs in. Also if you only want to allow access to a certain file then you would have to do some other things with sessions and the validation part of this script.
__________________
You can not say you know how to do something, until you can teach it to someone else. Last edited by timgolding; 05-23-2009 at 09:20 PM.. |
|
|
|
|
|
PM User | #9 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
Ok so I'm sure that method will work great for downloads. And thankyou so much! My second question here is if I have a flash video player (I'm using the JW player) will the php script above be able to deliver the same files into the player if the url is urlencoded? If this would work then disregard what I'm going to say next. I had an Idea and I don't know if this will work, but hear me out. What if I were to deny all access to a folder using the method described above with the .htaccess file. Then with a php function I was to stop it from being read when the user was logged in. This would make it so that the user would not be able to access the file unless logged in. The only probem with this is that it would have to ignore the file specifically for that user, and not disable the reading as a whole as disabling the file period would allow users to access the file when someone else was logged in.
|
|
|
|
|
|
PM User | #10 |
|
Regular Coder ![]() Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 28 Times in 27 Posts
![]() |
No.
You would have to change the headers to match the files to be able to give it to Flash. Here is a array of mimes: PHP Code:
__________________
Unlimit the Impossible
DO NOT CLICK ON THIS LINK!!!!! ||AWESOME Flash Stuff|||Good Flash Stuff|||Good PSD Files|| Sea4Me |
|
|
|
|
|
PM User | #11 |
|
New Coder ![]() Join Date: Mar 2009
Posts: 61
Thanks: 4
Thanked 4 Times in 4 Posts
![]() |
So would this work if the file was a .mp4 video file? (i changed the content type to the appropriate mime type...)
PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Tags |
| .htaccess, .htpasswd, authentication, login, php |
| Thread Tools | |
| Rate This Thread | |
|
|