2012-08-14 24 views
1

有人可以幫我猜這個代碼..這只是一個片段,我想我包括了我的問題所需的所有代碼。其實這個代碼來自hybridAuth。我的問題是,最後一行的「user_id」來自哪裏?我想知道,因爲$ _SESSION [「user」]給出了「id」的值。我想再拍$ _SESSION [」「]從數據庫,在那裏我可以把價值電子郵件添加(同一位置的是USER_ID的‘ID’的存在)請幫我猜這混合驗證碼

// create an instance for Hybridauth with the configuration file path as parameter 
$hybridauth = new Hybrid_Auth($hybridauth_config); 

// try to authenticate the selected $provider 
$adapter = $hybridauth->authenticate($provider); 

// grab the user profile 
$user_profile = $adapter->getUserProfile(); 

// load user and authentication models, we will need them... 
$authentication = $this->loadModel("authentication"); 
$user = $this->loadModel("user"); 

# 1 - check if user already have authenticated using this provider before 
$authentication_info = $authentication->find_by_provider_uid($provider, $user_profile->identifier); 

# 2 - if authentication exists in the database, then we set the user as connected and redirect him to his profile page 
if($authentication_info){ 
// 2.1 - store user_id in session 
$_SESSION["user"] = $authentication_info["user_id"]; 
+0

@邁克爾,如果我輸入var_dump($ authentication_info)將顯示在監視器上?不需要回聲? – 2012-08-14 12:40:32

+0

我將它擴展爲下面的答案。不需要echo - ['var_dump()'](http://php.net/manual/en/function.var-dump.php)是一個調試函數,它將顯示數組或對象的內容。不用於真正的顯示輸出,僅用於調試和可視化。 – 2012-08-14 12:42:23

回答

2

$authentication->find_by_provider_uid()調用返回一個關聯陣列,其中一個關鍵是user_id

看看其他列是由調用返回:

var_dump($authentication_info); 

如果email是數組中的鍵中,你可能會然後將其設置在$_SESSION

// Store the email into session if it is present in $authentication_info 
// Use whatever the appropriate key you find, be it email, email_address, user_email, whatever... 
$_SESSION['user_email'] = $authentication_info['email']; 
+0

if var_dump($ authentication_info);不會顯示在屏幕上,那麼我如何查看其他內容? – 2012-08-14 12:45:48

+0

您仍然可以嘗試print_r($ authentication_info)。 – vicrabb 2012-08-14 12:59:50

+1

@IvorySantos'var_dump()'將顯示在您的顯示器上。如果您出於某種原因未在網頁輸出中看到它,請查看網頁來源,然後您會在該網頁上看到它。 – 2012-08-14 13:03:58