.htpasswd, PHP, .htaccess Add User Crypt Unix Linux

I’m trying to add users to the .htpasswd file using a PHP script.

Can’t duplicate the crypt algorithm used by the Server.

This is on Unix hosting…any ideas?

tried crypt() ?

If ($PassGeneratedWithCrypt == crypt($UserEnteredPW, $PassGeneratedWithCrypt)) $Authorized = true;

It has something to do with the above…z