我有形成了登錄的一部分的兩個表/註冊系統:MySQL表結構問題(用戶登陸和userlogin_fb)
這些用戶登陸和userlogin_fb
用戶登陸涉及傳入網站登錄/註冊
userlogin_fb涉及傳入謝謝連接登錄/第一次登記
詳情@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中沒有創建新記錄。
但如果它們不存在,我可以爲它創建一個新的記錄。
然後,如果用戶試圖使用相同的用戶名/電子郵件註冊一個帳戶,我會將他們重定向到一個功能「合併」這兩個帳戶。
但這只是一個粗略的想法。請希望對此問題有更深入的瞭解。
希望我已經寫得夠好了!