Reputation: 57
While running the code on localhost it works perfect, when same on the server it won't redirect, after successful Facebook login the redirection is not working.
Server 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
source code
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);
}
?>
How can I enable in curl_exec()
in the server? and what is this curl_exec()
Upvotes: 0
Views: 443
Reputation: 1527
As the warning states, curl_exec()
is disabled. Curl is used to communicate with facebook and is required, so make sure you or your hosting provider enable it.
Upvotes: 1