感謝來自nickfrosty的YouTube教程,能夠在php中創建適當的註冊系統,我已經能夠將他的代碼從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 <[email protected]>";
$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頁面。
我的問題是,用戶點擊激活鏈接後,它是如何激活用戶的帳戶?我需要它能夠通過在$message .= "$site/activate.php?user=$getuser&code=$code\n";
以上的php中查找這個來識別用戶的用戶名和激活碼,然後在數據庫中,我需要它將該用戶的「激活」列從「0」更新爲「1」該用戶現在處於活動狀態。是下面的語句正確:
"UPDATE Teacher SET Active='1' WHERE TeacherUsername = '$getuser'"
"SELECT * FROM Teacher WHERE TeacherUsername='$getuser' AND Active='1'"
的activate.php頁面簡潔狀態的消息,說明該帳戶被激活。如果用戶已被激活,那麼我希望它顯示消息,指出用戶已被激活。
我有teacherId這是自動遞增,但我會用TeacherUsername因爲沒有老師可以有相同的用戶名。我會試試看看會發生什麼。乾杯 – user1394925
如果你不介意fabrice,爲了使它更容易,你能告訴我你將如何編寫activate.php頁面,以便我可以看到需要做什麼?我不急,但如果我能看到你將如何編寫代碼,那真的會給我一個開始,然後我可以使用和操縱代碼,以使其能夠在我的應用程序中工作。 – user1394925