Reply to Re: Protecting a whole directory - PHP Authentication

Your name:

Reply:


Posted by atpunkt@punktat.de on 08/28/07 22:09

Before we get too far off course here - I'd like to describe how I
handled jobs like this:

1- You need $_SESSION-Handling and some kind of Session-Based
Userlogin

2- You create an empty directory like /protected that has a .htaccess-
File with

Deny to All

and the abovementioned mod_rewrite line (slightly modified)

RewriteRule .* ../get_protected.php?file=$0 [L,QSA]

3- you put all the stuff to be protected in a 'data' directory OUTSIDE
the webserver path (you can leave it in /protected, but outside it's
even safer)

4- in get_protected.php you
- authenticate the user from his $_SESSION-data
- find the file by inspecting $_GET['file'] and checking if it
exists in your 'data' directories
- set the mimetype in the Header according to the filetype
- use readfile() to send the file to the user

*- expect webserver processing time to be higher than normal for
session handling and php in places where it usually isn't used (like
displaying images)

as said before: there's no way to do http-authentication (.htpasswd/
mod_auth_mysql) by setting the Authentication headers without
presenting the user with a browser-password-form. I had it working
once (by creating a meta-refresh to an URL that used the
http://user:password@www.myserver.com-Scheme) but that was rather
dirty, presented passwords in cleartext and was removed when IE6 no
longer accepted this password/URL scheme.

Hope this helps
Phil

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация