retrieve password from flat file<

liunx

Guest
hey guys :)

any way to have a simple script to protect a directory by pulling the password from a file instead of from a db. Trying to write a simple tutorial for password protection hence trying to avoid brining in databases :)

cheers


leowell if you want to protect the whole directory, try with .htaccess file in apache server

with php, you only be proctecting the php file itself, not the whole directory

but you could do something like

<?php
$users = parse_ini_file('passfile');
if (isset($users[$username])) {
//user exist
if ($users[$username]==$password) {
//password validate
}
}
?>

in passfile:
user1 = pass1
user2 = pass2

if you do that, you should encrypt your password!yeah i've already got .htaccess in the tutorial, i was just wondering if there was a php alternative.
THanks anyway, although i will keep theat snippet for protecting a single file handy if you don't mind, may come in handy :)

cheers

leoI don't know how to execute this exactly, but you could password protect a certain file the way illogique described. In the protected file start a session, and thus require the session to be open in order to access each other page within the directory.
 
Top