1

有人可以帮我猜出这段代码吗?这只是一个片段,我想我包含了我的问题所需的所有代码。实际上这段代码来自hybridAuth。我的问题是,最后一行的“user_id”来自哪里?我想知道,因为 $_SESSION["user"] 给出了“id”的值。而且我想制作另一个 $_SESSION[" "] 我可以在其中放置数据库中 email-add 的值(该 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"]; 
4

1 回答 1

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'];
于 2012-08-14T12:41:21.497 回答