2011-06-06 100 views
2

我有形成了登錄的一部分的兩個表/註冊系統:MySQL表結構問題(用戶登陸和userlogin_fb)

這些用戶登陸userlogin_fb

用戶登陸涉及傳入網站登錄/註冊

enter image description here

userlogin_fb涉及傳入謝謝連接登錄/第一次登記

enter image description here

詳情@http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/

如果用戶然而使用Facebook Connect登錄 - 系統檢查其是否已被註冊到數據庫,如果沒有,它會爲用戶創建一條新記錄:

if ($user){ 
// We have an active session, let's check if we have already registered the user 
$query = mysql_query("SELECT * FROM userlogin_fb WHERE oauth_provider = 'facebook' AND oauth_uid = ".$user_profile['id']); 
$result = mysql_fetch_array($query); 
// If not, let's add it to the database 
if(empty($result)){ 
    $query = mysql_query("INSERT INTO userlogin_fb (oauth_provider, oauth_uid, username, email) VALUES ('facebook', {$user_profile['id']}, '{$user_profile['username']}', '{$user_profile['email']}')"); 
    } 
     } elseif(isset($_SESSION['uid'])){ 
""; 
}else{ 
    // Anonymous user 
header('Location: index.php'); 
} 

當然,如果網站註冊AME用戶名/電子郵件地址存在,那麼它是不可能爲用戶註冊(和創建重複記錄)

//select all rows from our userlogin,userlogin_fb table where the emails match 
$query = sprintf("SELECT 1 
        FROM userlogin 
        WHERE `email` = '%s' 
        UNION ALL 
        SELECT 1 
        FROM userlogin_fb 
        WHERE `email` = '%s' ", 
        $email, $email); 
$res1 = mysql_query($query); 
$num1 = mysql_num_rows($res1); 
//if the number of matches is 1 
if($num1 >= 1) { 
    //the email address supplied is taken so display error message 
    echo '<p class="c7">The <b>e-mail</b> address you supplied is already taken. Please go <a href="register.php">back</a> and provide a new one.<br><img src="resources/img/spacer.gif" alt="" width="1" height="15"></p>'; 
    include_once ("resources/php/footer.php");   
    exit; 
} else  

//select all rows from our userlogin,userlogin_fb table where the usernames match 
$query2 = sprintf("SELECT 1 
        FROM userlogin 
        WHERE `username` = '%s' 
        UNION ALL 
        SELECT 1 
        FROM userlogin_fb 
        WHERE `username` = '%s' ", 
        $username, $username); 
$res2 = mysql_query($query2); 
$num2 = mysql_num_rows($res2); 
//if the number of matches is 1 
if($num2 >= 1) { 
    //the username supplied is taken so display error message 
    echo '<p class="c7">The <b>username</b> you supplied is already taken. Please go <a href="register.php">back</a> and provide a new one.<br><img src="resources/img/spacer.gif" alt="" width="1" height="15"></p>'; 
    include_once ("resources/php/footer.php");   
    exit; 

現在我遇到的問題是這樣的。每當用戶通過網站註冊並使用Facebook連接登錄時,我發現無論userlogin_fb表中是否創建了重複記錄。

因爲我不想在兩個表中有任何重複的用戶名/電子郵件地址以及「兩種不同的用戶登錄模式」,每種模式都包含與用戶有關的不同信息集合,我怎樣才能將兩者整合?

最好時使用Facebook Connect,我會運行一個查詢檢查用戶登陸表,看是否有重複的用戶名首先的存在,如果記錄具有相同的用戶名存在使用這些細節

用戶登錄/電子郵件地址userlogin然後在userlogin_fb中沒有創建新記錄。

但如果它們不存在,我可以爲它創建一個新的記錄。

然後,如果用戶試圖使用相同的用戶名/電子郵件註冊一個帳戶,我會將他們重定向到一個功能「合併」這兩個帳戶。

但這只是一個粗略的想法。請希望對此問題有更深入的瞭解。

希望我已經寫得夠好了!

回答

2

Facebook更新他們的用戶ID,你想BIGINT(15),雖然正如Sascha Galley VARCHAR所說的是未來的保障。

我有3個表格:網站的用戶,臉書用戶和臉書聯合用戶。

數據獨立存儲在前兩個表中,即相同的電子郵件可以在前兩個表中出現一次,這並不重要,他們可以登錄他們想要的任何一個。

如果服務員檢測到用戶和fb用戶,並且他們希望關聯這兩個賬戶,則在第三個表中創建一個新行,並且賬戶信息結合在該表中(發佈計數,評論...)。