PHP 5.4.x makes a few changes to the php.ini
file which causes the Facebook PHP SDK to break, and after a few hours of searching, I’ve come across a solution that worked for me. The problem was that after authenticating an user using $facebook->getLoginUrl()
, the subsequent $facebook->getUser()
call would fail, retuning 0
.
The issue is with the PHP SDK, which relies on $_REQUEST
from the server, which has changed in PHP 5.4.0 because of default php.ini
settings having been changed.
The solution is to change the SDK’s getCode()
method (found in base_facebook.php
file to work around the issue:
Replacing:
With:
The code simply combines the $_GET
, $_POST
and $_COOKIE
arrays as with how $_REQUEST
used to work prior to PHP 5.4.0. Hope this solution works for you as it did for me.
The change should then correctly return a valid User ID when calling $facebook->getUser()
, instead of 0
. This code also works in CodeIgniter, which is where I first tested the solution.