Create new HTTP auth credentials using PHP instead of shell

邮差的信 提交于 2019-12-10 16:54:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!