在localhost上运行代码时,它完美无缺,在服务器上运行时它不会重定向,在Facebook登录成功后,重定向无法正常工作。
服务器PHP 5.4.x
Facebook PHP SDK v4
1. PHP Warning: curl_exec() has been disabled for security reasons in /src/Facebook/HttpClients/FacebookCurl.php on line 77
2. PHP Catchable fatal error: Argument 4 passed to Facebook\FacebookResponse::__construct() must be of the type array, null given, called in src/Facebook/FacebookClient.php on line 225 and defined in /src/Facebook/FacebookResponse.php on line 75
源代码
fbconfig.php
<?php
require_once 'src/Facebook/autoload.php';
use Facebook\Facebook;
use Facebook\FacebookResponse;
use Facebook\GraphNodes\GraphUser;
use Facebook\Exceptions\FacebookAuthenticationException;
use Facebook\Exceptions\FacebookSDKException;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Helpers\FacebookRedirectLoginHelper;
use Facebook\FacebookClient;
use Facebook\HttpClients\FacebookHttpClientInterface;
session_start();
$fb = new Facebook(['app_id' => 'xx',
'app_secret' => 'yy',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = (string)($helper->getAccessToken());
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo $accessToken;
if (isset ($accessToken))
{
$fb->setDefaultAccessToken($accessToken);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me');
$user = $response->getGraphUser();
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$_SESSION['FULLNAME']=$user['name'];
$_SESSION['FBID']= $user['id'];
header("Location: index.php");
}
else
{
$permissions = ['email']; // optional
$loginUrl = $helper->getLoginUrl("http://x.com/fbconfig.php",$permissions);//,$permissions);
header("Location: ".$loginUrl);
}
?>
如何在服务器中的curl_exec()
中启用?这是什么curl_exec()