I don't know what you mean when you say you want the PHP script to "interact" with the htaccess file. An .htaccess file is just a text file with security directives in it. These directives are interpreted by the Apache web server that controls directory security.
You can write a script that can manipulate the text directives in this file, but I am not sure whether Apache would have to be restarted each time for those directives to take effect.
Also, htaccess is worthless without the corresponding information being blaced into the htpasswd file. You can't (well, maybe you can but you shouldn't) write a script that can manipulate encrypted user and password information in the password file. This is because your script is running as NOBODY (at least it better be) and the password files are owned by ROOT.
-- Rich