问题
I know that it's possible to add new HTTP auth credentials through this shell script:
htpasswd -c .htpasswd testing
Is it possible to achieve the same with a PHP script? I know I could use a regular PHP auth system, but that's not what I'm looking for.
回答1:
You can execute this command with system or exec to add your users.
I've created a code snippet that might work for you:
<?php
define('HTPASSFILEPATH', '.htpasswd');
function addUser($pUser, $pPass)
{
exec("htpasswd -cb " . HTPASSFILEPATH . " ${pUser} ${pPass}");
}
?>
And remember, the htpasswd
tool should be in your PATH
来源:https://stackoverflow.com/questions/8275051/create-new-http-auth-credentials-using-php-instead-of-shell