Create new HTTP authentication credentials using PHP instead of shell

I know that you can add new HTTP authentication data through this shell script:

htpasswd -c .htpasswd testing 

Is it possible to achieve the same result with a PHP script? I know that I can use the regular PHP auth system, but this is not what I am looking for.

+4
source share
1 answer

You can execute this command with system or exec to add your users.

I 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 that the htpasswd tool must be in your PATH

+3
source

Source: https://habr.com/ru/post/1383137/


All Articles