请帮我猜一下这个hybridAuth代码

时间:2012-08-14 12:35:19

标签: php hybridauth

有人可以帮我猜出这段代码..这只是一个片段,我想我已经包含了我的问题所需的所有代码。实际上这段代码来自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"]; 

1 个答案:

答案 0 :(得分: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'];