抱歉这个问题的不断更新!从现在开始,我将一个人离开。
我可以通过 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>