I had this problem too.
On my site I also set a cookie and $_SESSION variable by the name 'state'. This was causing a conflict with the Facebook class since the FB class uses the same key name.
Below is my resolution for others with this issue:
Facebook PHP SDK v3.2.3
What were going to do is swap out certain instances of 'state' with 'fb_state'.
EDIT (Marcus): I also swapped out all instances of $_REQUEST['state'] with $_GET['state']. This would force the application to get the 'state' value from the URL post user authorization as $_REQUEST will pick up any stored 'state' cookie you might already have. And in my case, there was one.
E.g. www.example.com/?code=AQA5cjNZ8iuZ...&state=48a4a0a89ebb0c568f713fabebcd4899#=
My previously stored 'state' cookie due to previous activity on my own site: ON
echo $_REQUEST['state']; // produces 'ON'
echo $_GET['state']; // produces 48a4a0a89ebb0c568f713fabebcd4899
On my site. And I wasn't about to go changing my site's method of storing cookies and session variables on the server just for the FB SDK.
Without changing $_REQUEST to $_GET, the getCode() function will return false because:
if ($this->state === $_REQUEST['state']) {
Will not resolve. The actual compare would be 48a4a0a89ebb0c568f713fabebcd4899 against 'ON' in my case.
src/facebook.php
public function __construct($config) {
...
$state = $this->getPersistentData('state'); // line 67
// change to
$state = $this->getPersistentData('fb_state');
protected static $kSupportedKeys =
array('fb_state', 'code', 'access_token', 'user_id'); // line 83
src/base_facebook.php
$state = $this->getPersistentData('fb_state'); // line 263
$this->clearPersistentData('fb_state'); // 730
$this->setPersistentData('fb_state', $this->state); // line 776
Hope this helps somebody in the future.