我驗證用戶帳戶時,下面的成功:電子郵件驗證,但不在服務器上
if (!empty($_GET['email']) AND !empty($_GET['hash'])) {
// sanitize $_GET data
$_GET = DB::instance(DB_NAME)->sanitize($_GET);
// declare variables for ease of use for $_GET data
$email = ($_GET['email']);
$hash = ($_GET['hash']);
// make sure the data we $_GET is the data we are expecting (matches in the database)
$match = DB::instance(DB_NAME)->select_rows("SELECT email, verify_hash, verified FROM users WHERE email='" . $email . "' AND verify_hash='" . $hash . "' AND verified='0'");
$match = count($match);
// if there is a match, activate the account
if ($match > 0) {
// change 'verified' column from 0 to 1
$q = array('verified' => 1);
$verify_user = DB::instance(DB_NAME)->update('users', $q, "WHERE email='" . $email . "' AND verify_hash='" . $hash . "' AND verified='0'");
// send success message
$this->template->content->message = "Your account has been activated, you can now login";
// get user type from users table
$q1 = "SELECT * FROM users WHERE email = '" . $email . "'";
$result = DB::instance(DB_NAME)->select_row($q1, 'array');
// if we have a teacher, update the teachers table
if ($result['type'] == 'teacher') {
// prepare default pic and username
$data = Array(
'user_id' => $result['user_id'],
'avatar' => 'blank_teacher.png',
// need a username to access profile view -- if not random enough, specify ON DUPLICATE KEY condition
'user_name' => $result['first_name'] . rand()
);
$update_teacher = DB::instance(DB_NAME)->insert('users_teachers', $data);
// prevent page errors from SQL query failing when new teachers don't have at least one subject that they teach
$data = Array(
// '32' stands for 'other' subject
'subject_id' => '32',
'users_user_id' => $result['user_id']
);
$update_at_least_one_subject = DB::instance(DB_NAME)->insert('teachers_subjects', $data);
}
} else {
// No match: invalid url or account has already been activated.
$this->template->content->message = "The url is either invalid or you already have activated your account.";
}
} else {
// Invalid approach
$this->template->content->message = "Invalid approach, please use the link that has been sent to your email.";
}
奇怪的是(至少對我來說),這工作完全在我的本地主機,但悲慘地在我的現場服務器上。我基本上不能獲得通過電子郵件收到上班的URL,它看起來像下面:
myurl.com/users/[email protected]&hash=ccb1d45fb76f7c5a0bf619f979c6cf36
我不斷收到我自己的錯誤信息:「無效的方法」這(邏輯)似乎要發出時,無論是兩個$ _GET變量之一,'email'或'hash'是空的。在我看來,他們絕對不是空的。
無論如何,我不太清楚如何解決本地和現場之間的差異。其他一切似乎都行得通。最初我正在檢查以確保'email'和'hash'也是'set',如isset('email'),所以我刪除了該功能,但那並沒有解決問題。
UPDATE:
我htaccess文件內容:
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
如果包含唯一ID,爲什麼要在URL中包含電子郵件?所有你需要的是'email_signup_verification?hash = ccb1 ....'。 – meagar
@meagar我從驗證網址中刪除了電子郵件,仍然沒有骰子......在本地但在服務器上運行 – compguy24
這是一個簡單的觀察,並不是解決您的問題的建議。 – meagar