Add or delete users in .htpasswd online
include("./class.Htpasswd.php3");
/* Please modify the path of this .htpasswd file
*/
$htpasswdfile = "/usr2/amitc/ .htpasswd";
// Please do not modify this line
echo '
}
else {
echo "
";
echo "You just performed this operation, please check
";
echo "You want to change user $username and password $password = [$doop]
";
$handle = new Htpasswd($htpasswdfile);
switch ($doop) {
case 'add':
print "User
";
$retval = $handle->addUser($username, $password);
if($retval) {
print "User[$username] joined successfully!
" ;
} else {
print "Failed to join user [$username].
";
}
break;
case 'change':
print 'Change password
';
$retval = $handle ->changePass($username, $password);
if($retval) {
print "[$username]'s password was changed successfully.
";
} else {
print "[$username]'s password Modification failed.
";
}
break;
case 'delete':
print 'Delete user
';
$retval = $handle->deleteUser($username);
if($ retval) {
print "[$username] was deleted.
";
} else {
print "An error occurred while deleting [$username].
";
}
break;
case 'verify ':
print 'Code to verify user's password
';
$retval = $handle->verifyUser($username, $password);
if($retval) {
print "[$username] verifies okay with password [$password]
";
} else {
print "Verify Error for [$username] with [$password] (wrong password or user doesn't exist!)
";
}
break;
default:
print 'Do you want to break?
';
}
echo "";
}
?>
The above has introduced the online addition and deletion of users in htpasswd, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.