感谢Nickfrosty提供的关于能够在 php 中创建适当的注册系统的 youtube 教程,我已经能够将他的代码从mysql转换为mysqli,并且能够在用户注册后通过电子邮件发送激活链接。
下面是在数据库中插入注册详细信息并在用户注册后将消息和激活链接发送到用户电子邮件的代码。
$code = md5(rand());
$insertsql = "
INSERT INTO Teacher
(TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername, TeacherPassword, Code)
VALUES
(?, ?, ?, ?, ?, ?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}
$insert->bind_param("sssssss", $getfirstname, $getsurname,
$getemail, $getid, $getuser,
$teacherpassword, $code);
$insert->execute();
if ($insert->errno) {
// Handle query error here
}
$insert->close();
$site = "http://helios.hud.ac.uk/......../Mobile_app";
$webmaster = "Mayur Patel <.......@hud.ac.uk>";
$headers = "From: $webmaster";
$subject = "Activate Your Account";
$message = "Thanks for Registering. Click the link below to Acivate your Account. \n";
$message .= "$site/activate.php?user=$getuser&code=$code\n";
$message .= "You must Activate your Account to Login";
if(mail($getemail, $subject, $message, $headers)){
$errormsg = "You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b>";
$getfirstname = "";
$getsurname = "";
$getid = "";
$getuser = "";
$getemail = "";
}
但我现在有一个问题。如果我单击该链接,它会将用户导航到该activate.php
页面。
我的问题是:用户点击激活链接后,如何激活用户的账户?我需要它能够通过在上面的 php 中查找它来识别用户的用户名和激活码$message .= "$site/activate.php?user=$getuser&code=$code\n";
,然后在数据库中我需要它Active
从0 to
1` 更新该用户的列,以便用户现在处于活动状态。下面的说法是否正确:
"UPDATE Teacher SET Active='1' WHERE TeacherUsername = '$getuser'"
"SELECT * FROM Teacher WHERE TeacherUsername='$getuser' AND Active='1'"
该activate.php
页面仅显示一条消息,说明该帐户已激活。如果用户已经被激活,那么我希望它显示用户已经被激活的消息。