How do I register a new username/password on apache (.htaccess and .htpasswds) using php?
A:
If the user running the php script has permissions to write in your .htpasswd file (which, btw, can be a big security risk), you can write into it like you would with any regular file:
$filename = "path-to-htpasswd-file";
$content = $user.":".crypt($pass)."\r\n";
if (is_writable($filename)) {
$handle = fopen($filename, 'a');
if ($handle) {
fwrite($handle, $somecontent);
fclose($handle);
}
}
A. M.
2010-08-25 23:04:52