Hi everyone please take a look at the code below, I own a website which this code is held on.
Why its on my website is that the company that operates my payment system action this script to add and delete usernames from my .htaccess files.
I would like to operate a similar system on my website, what would I need to do to call the script to add a username and password to another website which I would have registered on my system?
<?
// Add a username/password the password file or
// Delete username(s) from the password
//------------------------------------------------------------------------------
// Parameters:
// $username : username
// $passwd : password
//------------------------------------------------------------------------------
// returns:
// OK - Succesfully added/deleted the username/password
// FAILED - insert into the table failed.
//------------------------------------------------------------------------------
header ("Pragma: no-cache");
header ("Expires: -1");
$passfile ='/<path_to_passwordfile>/.htpasswd';
//------------------------------------------------------------------------------
// Delete username(s) from the password
//------------------------------------------------------------------------------
// Parameters:
// $user : username
//------------------------------------------------------------------------------
// returns:
// OK - Succesfully deleted the username/password
// FAILED - access to passfile denied
//------------------------------------------------------------------------------
function DeleteUser($u)
{
global $passfile;
$allusers=file($passfile);
$done=0;
$newusers='';
foreach($allusers as $line)
{
$line=trim($line);
list($user,$pass)=split(':',$line);
if($user!='' && strcmp($u,$user)!=0)
{
$newusers.="$line\n";
}
else $done++;
}
if($done)
{
if($fpass=fopen($passfile,'w'))
{
flock($fpass,2);
fputs($fpass,$newusers);
ftruncate($fpass,ftell($fpass));
fclose($fpass);
echo "OK";
}
else echo "FAILED, ACCESS TO PASSFILE DENIED";
}
}
if(($username=='' || $username=='?') && $passwd=='') {
echo "FAILED";
exit();
}
DeleteUser($username);
if($p!='')
{
// Add user
if($h=fopen($passfile,'a'))
{
$pw=crypt($passwd);
fputs($h,"$username:$pw\n");
fclose($h);
echo "OK";
}
else echo "FAILED, ACCESS TO PASSFILE DENIED";
}
?>