在这里,我之前已经解释了如何创建登录系统。检查这篇文章。这可能会帮助你。
开源富 HTML 编辑器
以及关于发送邮件进行激活。您需要将以下内容附加到上述解释的代码中。
activation_string
向表用户添加一个额外的列。现在你的决赛桌应该是这样的。
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`activation_string` varchar(50) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
);
该activation_string
列将保存要发送到用户电子邮件的激活字符串。这样当用户点击它时,用户帐户就会被激活。现在使用以下函数生成激活字符串。
function generateActivationString() {
$randomSalt = '*&(*(JHjhkjnkjn9898';
$uniqId = uniqid(mt_rand(), true);
return md5($randomSalt.$uniqId);
}
现在使用注册表单代表用户。在提交表单时,您必须执行以下操作。
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string(sha1($_POST['password']));
$activationString = generateActivationString();
mysql_query("INSERT INTO users (email,password, activation_string) VALUES('$name','$password','$activationString')");
同时向用户发送一封电子邮件,其中激活字符串表示为 URI。检查下面的代码如何做到这一点。
$email = $_POST['email'];
$message = 'http://mysite.com/activate.php?confirm='.$activationString;
$to = $email;
$subject = 'User Account Confirmation';
$body = $message . PHP_EOL;
mail($to, $subject, $body);
然后编写另一个脚本来验证字符串,如果验证激活字符串,则将 status 中的值更新为 1。
希望这可以帮助您了解您应该做什么。