$ facebook-> getUser()在转移到新主机后返回0

I'm using Facebook PHP SDK 3.1.1. This code works fine for me on my previous hosting. I've just moved it to BlueHost and the value of $user is always 0 even when user already logged in:

$facebook = new Facebook(array(
  'appId'  => FACEBOOK_APIKEY,
  'secret' => FACEBOOK_SECRET_KEY,
));

$user = $facebook->getUser();

Any idea why this can happen?

The getUser() function uses the $_REQUEST['signed_request']) global.

And since you said you recently switched hosting accounts, it is possible that the server is configured either to turn off $_REQUEST or somehow override it.

You can check these php.ini variables, because they affect $_REQUEST:

  • variables_order
  • request_order

The see these variables do phpinfo(); in your template, which is going to print out all the necessary information.

http://php.net/manual/en/function.phpinfo.php

Otherwise, you might need to contact your hosting provider and ask about the $_REQUEST global, to see if you can use it.