Hi!
The script below should add new logins/passes to the .htpasswd-file. But there is a problem! When you add a new member (user/pass) with the form, it writes over the old usernames and passwords! Not so good no...
It should add at the bottom of the .passwd-file, not delete the present users/passwds...
Can anyone see what\'s wrong with the code?
<?
if (($user) && ($passwort))
{
$pfad = $DOCUMENT_ROOT . dirname($PHP_SELF) . \"/.htpasswd\";
$safe= dirname ($PHPSELF);
$htaccess= fopen(\".htaccess\", \"w\");
$htpasswd= fopen(\".htpasswd\", \"w\");
$htaccess_text = \"AuthType Basic\\n\".
\"AuthName \\\"Member\\\"\\n\".
\"AuthUserFile $pfad\\n\".
\"require valid-user\\n\";
for ($i = 0; $i < count ($user); $i++)
{
$htpasswd_text .= \"$user[$i]:\".crypt($passwort[$i],CRYPT_STD_DES).\"\\n\";
}
fputs($htaccess, $htaccess_text);
fputs($htpasswd, $htpasswd_text);
fclose($htaccess);
fclose($htpasswd);
echo nl2br($htaccess_text);
echo \"<p><hr></p>\";
echo nl2br($htpasswd_text);
echo \"<p><hr></p>\";
}
?>
<HEAD>
<TITLE> New member </TITLE>
</HEAD>
<BODY>
<FORM METHOD=\"POST\" ACTION=\"<? echo $PHP_SELF; ?>\">
<p>User: <INPUT TYPE=\"TEXT\" NAME=\"user[]\"></p>
<p>Passwd: <INPUT TYPE=\"TEXT\" NAME=\"passwort[]\"></p>
<p><INPUT TYPE=\"submit\" VALUE=\"Skapa\"></p>
</FORM>
</BODY>