我可以使用facebook javascript sdk注册并成功将fb登录信息存储到WP_user表中,但是它还没有重定向到登录页面
这是我成功登录后的代码
$info1 = array();
$info1['user_login'] = $info['user_login'];
$info1['user_password'] = $info['user_pass'];
$info1['remember'] = true;
$user = wp_signon( $info1, false );
echo json_encode(array('loggedin'=>true, 'message'=>__($login.' successful, redirecting...')));
wp_redirect(home_url());
这是header.php上的代码,用于检查用户是否已登录
<?php if (is_user_logged_in()) { ?>
<a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>
<?php } else {
?>
<a>Login</a>
<a>register</a>
<?php } ?>
:我还尝试了一个用于登录页面的脚本,并登录并显示欢迎
登录后用户
<?php
// Enter the app id and secret below
define('YOUR_APP_ID', 'xxxxxxxxxxxx');
define('YOUR_APP_SECRET', 'xxxxxxxxxxx');
function get_facebook_cookie($app_id, $app_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $app_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
//$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$cookie['access_token'//])
$user = viacurl('https://graph.facebook.com/me?access_token='.$cookie['access_token']);
function viacurl($location){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $location);
curl_setopt($ch, CURLOPT_HEADER, false);
$out=curl_exec($ch);
curl_close($ch);
return rtrim($out,1);
}
//);
?>
<div id="fb-root"></div>
<?php
print_r($user);
if ($user->id) { ?>
<p>Welcome <?= $user->name ?></p>
<?php } else { ?>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
FB.init({
appId:<?php print YOUR_APP_ID; ?>, cookie:true,
status:true, xfbml:true
});
</script>
<fb:login-button>Login to Eureka!</fb:login-button>
<?php } ?>
</div>
但这似乎也很明显
我看过一些帖子,据说wordpress会照顾会话本身。
我是否需要使用php会话或wordpress可以自己做?如果遗漏了什么请建议......
答案 0 :(得分:0)
注意:wp_redirect()不会自动退出,并且几乎总是会跟着调用退出;:
angular.module('myApp', [])
.directive('maskInput', function() {
return {
require: "ngModel",
restrict: "AE",
scope: {
ngModel: '=',
},
link: function(scope, elem, attrs) {
var orig = scope.ngModel;
var edited = orig;
scope.ngModel = edited.slice(4).replace(/\d/g, 'x') + edited.slice(-4);
elem.bind("blur", function() {
var temp;
orig = elem.val();
temp = elem.val();
elem.val(temp.slice(4).replace(/\d/g, 'x') + temp.slice(-4));
});
elem.bind("focus", function() {
elem.val(orig);
});
}
};
})
.controller('myCtrl', ['$scope', '$interval', function($scope, $interval) {
$scope.creditCardNumber = "1234567890123456";
}]);
wp_redirect应始终包含在get_header();
之上我建议用add_action init包含它。 https://codex.wordpress.org/Plugin_API/Action_Reference/init