I am trying to build a facebook user login with php. I am able to get user info but every login creates an error log on my server CSRF state token does not match one provided. after login success.
I have found many tutorials around google for creating a facebook login. I have also found a few other posts for the same issue. They seem to blame calling getLoginUrl() more than once, which I am not doing. And since I am using the example that comes with the sdk, I am confused why it is broken out of the box.
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$logoutUrl = $facebook->getLogoutUrl();
echo "<a href=" . $logoutUrl . ">Logout</a><br><br>";
print_r($user_profile);
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else {
$loginUrl = $facebook->getLoginUrl();
echo "<a href=" . $loginUrl . ">Login</a>";
}
?>