2012-09-18 59 views
2

對不起,這個問題不斷更新!我將從現在開始獨自離開。以WordPress用戶登錄Facebook用戶

我可以通過Facebook登錄註冊新用戶到我的WordPress數據庫中。但我很難將用戶登錄到Wordpress中。

它應該通過wp_signon($ credentials,$ secure_cookie)完成,但我沒有得到它將Wordpress用戶登錄到Wordpress中。用戶仍然需要通過Wordpress登錄表單。

該錯誤消息我得到的是

Warning: Cannot modify header information - headers already sent by (output started at 
.../file shown below.php:36) in ..../wp-includes/pluggable.php on line 680-682 

任何幫助將非常感激!

<?php 
try{ 
include_once "src/fbaccess.php"; 
}catch(Exception $e){ 
error_log($e); 
} 
try{ 
require_once "wp-blog-header.php"; 
}catch(Exception $e){ 
error_log($e); 
} 

try{ 
require_once "wp-includes/registration.php"; 
}catch(Exception $e){ 
error_log($e); 
} 

try{ 
require_once "wp-includes/user.php"; 
}catch(Exception $e){ 
error_log($e); 
} 

?> 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <title>Florian's Facebook login</title>  

</head> 
<body> 
<!-- Copy the below code to display FB Login/Logout button --> 
<?php if ($user): ?> 
    <a href="<?php echo $logoutUrl; ?>">Logout</a> 
<?php else: ?> 
    <div> 
    <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> 
    </div> 
<?php endif ?> 
<!-- Copy the above code to display FB Login/Logout button --> 

<h3>PHP Session</h3> 
<pre><?php print_r($_SESSION); ?></pre> 

<?php if ($user): ?> 
    <h3>You</h3> 
    <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> 

    <h3>Your User Object (/me)</h3> 
    <?php $newusername = $user_profile [first_name]; ?> 
<?php $newlastname = $user_profile [last_name]; ?> 
    <?php $newemail = $user_profile [email]; ?> 
    <?php $newlocation = $user_profile [location]; ?> 

<?php else: ?> 
    <strong><em>You are not Connected.</em></strong> 
<?php endif ?> 

<?php 
$newpassword = '1234'; 

$creds = array(); 
$creds['user_login'] = $newusername; 
$creds['user_password'] = $newpassword; 
if (!empty($remember)){ 
    $creds['remember'] = true; 
} 

$userWP = wp_signon($creds, true); 

if(is_wp_error($userWP)) { 
    echo $user->get_error_message(); 
} 
else { 
} 
{ 
// Check that user doesn't already exist 
if (!username_exists($newusername) && !email_exists($newemail)) 
{ 
// Create user and set role to subscriber 

$user_id = wp_create_user($newusername, $newpassword, $newemail); 
if (is_int($user_id)) 
{ 
    $wp_user_object = new WP_User($user_id); 
    $wp_user_object->set_role('subscriber'); 
    echo 'Successfully created new subscriber user.'; 
} 

else { 
    echo 'Error with wp_create_user. No users were created.'; 
} 
} 
else { 
    echo 'This user or email already exists. Nothing was done.'; 
} 
} 

?> 
</body> 
</html> 
+1

我們不會侮辱你,但你可以多描述一下*不要讓它工作*的意思?你有錯誤嗎?意外的結果? – Tchoupi

+0

它不會以WordPress用戶身份登錄Facebook用戶。這意味着在登錄我的Facebook應用程序並在Wordpress數據庫中創建新用戶之後,我仍然需要通過wordpress表單登錄。 –

+0

@Mathieu Imbert:我的澄清能幫助你嗎? –

回答

0

,如果您登錄壞了,你可能想看看這個:

if (is_wp_error($userWP)) 
    echo $user->get_error_message(); 

wp_signon可以醚返回WP_User或WP_Error,你可以在這裏看到http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/user.php#L55

您可能還需要採取一看http://codex.wordpress.org/Function_Reference/wp_signon

請發表WP_Error留言,我們會找到方法:)

+0

嗨,約翰,我得到的錯誤消息與上面的更新代碼是警告:不能修改標題信息 - 頭文件已經發送(輸出開始在/文件上面:36)在.../wp-includes/pluggable.php在線680-682 –

+0

然後請做一個_search_這個錯誤信息......你不是世界上第一個遇到它的人。 – CBroe

+0

我確實搜索過,並按照我找到的建議,但沒有成功。這可能是我上面的文件結構嗎?它是一個php文件,但也包含html代碼。錯誤指向上述文件<?php if($ user):?>中的這一行 –