2013-12-08 36 views
0

我驗證用戶帳戶時,下面的成功:電子郵件驗證,但不在服務器上

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] 
+1

如果包含唯一ID,爲什麼要在URL中包含電子郵件?所有你需要的是'email_signup_verification?hash = ccb1 ....'。 – meagar

+0

@meagar我從驗證網址中刪除了電子郵件,仍然沒有骰子......在本地但在服務器上運行 – compguy24

+0

這是一個簡單的觀察,並不是解決您的問題的建議。 – meagar

回答

0

有沒有可能是你的服務器上重寫規則讓你懷念的查詢字符串? 您可以檢查.htaccess文件。

+0

剛剛添加.htaccess文件內容的問題 - 任何想法如何可能會影響查詢字符串? – compguy24

+0

'RewriteRule。* index.php/$ 0 [PT,QSA,L]',將[QSA]修飾符添加到您的重寫規則 表示查詢字符串追加 – kingtreecome