您可以将BOOLEAN列添加到用户表user_approved,并将其默认设置为0。
当新用户注册时,使用PHP邮件功能向管理员发送电子邮件,要求批准:
$to = 'admin@yourwebsite.com';
$subject = 'User needs approval';
$message = 'The user {username} needs your approval' .
'----------------------------------- ' . "\r\n" .
'Accept: ' . $accept_link . "\r\n" .
'Decline: ' . $decline_link . "\r\n";
$_headers = 'From:admin@yourwebsite.com' . "\r\n"; // Set FROM headers
mail($to, $subject, $message, $headers); // Send the email可以使用PHP哈希函数生成accept_link和decline_link
例如,您可以使用SHA512哈希:
$accept_link = "yourwebsite.com/approval.php?e=" . $email . "&h=" . hash('sha512', 'ACCEPT');
$decline_link = "yourwebsite.com/approval.php?e=" . $email . "&h=" . hash('sha512', 'DECLINE');在PHP脚本approval.php中,您只需检查获取变量并检查管理员是否要接受或拒绝注册请求。
$hash = $_GET['h'];
$email = $_GET['e'];
if($hash == hash('sha512', 'ACCEPT')){
//ACCESS MYSQL DATABASE
//FIND THE USER AND SET user_approved = 1
//WHERE email = $email
}else if($hash == hash('sha512', 'DECLINE')){
//MAIL THE USER NOTIFYING THAT THE ACCOUNT HAS NOT BEEN APPROVED
}