I am having problems with using the Facebooks php sdk. When printing the
$facebook->getSignedRequest() the print doesn't show any 'page' or 'user' values.
I also tryed to print the $_REQUEST['signed_request'] and all I get is
Notice: Undefined index: signed_request
Could it be some settings in my php.ini file that I've missed to do?
Thanks for the help!
This is only going to possibly solve half the issue, but remember $_REQUEST['signed_request'] not $_REQUEST('signed_request');
EDIT: Ignore the last part as you mentioned, here is your answer:
You are getting variables just not the ones you want. It is returning a signed request, and you need to decrypt the request using your private key. Heres how:
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
Pass the signed request and your app secret into that and it will return your array. Im sure there is a way to do it with the Facebook SDK but im not not sure as I don't use it.
More Info: https://developers.facebook.com/docs/authentication/signed_request/
Goodluck!