Forum Moderators: coopster
.htaccess/.htpasswd user authentication is handled entirely by the Apache server and doesn't interact with PHP (although you can pull the username into PHP after they have logged in by accessing the appropriate server variable).
If you are authenticating users using an HTML form and PHP you will need to start a PHP session for the user when they log in, and check for a valid user on a page by page basis. This is a big subject, but PHPBuilder has a few articles on session management here:
[phpbuilder.com...]
ex: html form
<input type=text name=USER><input type=text name=PASS>
ex: php script
$htp = fopen(".htpasswd",w);
fputs($htp,$file); // $file being the .htpasswd file
ex: created .htpasswd file
user:4j.tBVk51Uhjg
<?
echo "user:";
$chars = array_merge(range('a','z'),range('A','Z'),range(0,9));
$newpass = 'pass';
for($i=0;$i<2;$i++) { $salt .= $chars[mt_rand(0,count($chars)-1)]; }
echo crypt($newpass,$salt);
?>
i know it is really igly, but i just wanted to show how its done...thanks guys
BTW i found it with this search in google
"htpasswd site:php.net" it was the first one
crypt()routine. Files managed by
htpasswdmay contain both types of passwords; some user records may have MD5-encrypted passwords while others in the same file may have passwords encrypted with
crypt().