2011-11-03 85 views
0

我使用Twitter登錄爲我的網站,當用戶輸入他的Twitter登錄ID然後如何檢查此用戶已註冊在我的數據庫或新用戶。檢查嘰嘰喳喳登錄ID已經在數據庫

和1個東西 - 當我打印print_r($ user_info);然後我接到

stdClass Object 
(
[id_str] => 395809931 
[default_profile] => 1 
[time_zone] => 
[created_at] => Sat Oct 22 08:45:33 +0000 2011 
[profile_text_color] => 333333 
[protected] => 
[default_profile_image] => 1 
[profile_background_image_url] => http://a0.twimg.com/images/themes/theme1/bg.png 
[name] => om nath 

多........ ) 我怎麼能閱讀和使用本[ID_STR。

回答

1

那麼,對於初學者,您可以通過訪問$user_info對象的id_str屬性來拉出id_str

$id = $user_info->id_str; 

之後,搞清楚他們是否已經註冊取決於你如何存儲你的用戶。 Twitter的oauth是登錄的唯一機制嗎?如果是這樣,那麼你可以使用id_str作爲你的用戶表的主鍵。然後,您只需對數據庫執行查詢,看看它們是否存在。假設mysql,你的查詢就像

SELECT user_id FROM users WHERE user_id = '$id';