Skip to content

Instantly share code, notes, and snippets.

@chrismendis
Created April 20, 2011 19:31
Show Gist options
  • Save chrismendis/932450 to your computer and use it in GitHub Desktop.
Save chrismendis/932450 to your computer and use it in GitHub Desktop.
Returns a JSON object containing the signed request that Facebook sends to your FB app as a POST variable.
$req = htmlspecialchars($_POST['signed_request']);
$reqParts = split('\.', $req);
$encodedValue = $reqParts[1];
$encodedValue = preg_replace('/\+/', '-', $encodedValue);
$encodedValue = preg_replace('/\//', '_', $encodedValue);
$pad = strlen($encodedValue) % 4;
if ($pad > 0) {
$pad = 4 - $pad;
}
$encodedValue = str_pad($encodedValue, $pad, '=');
$result = json_decode(base64_decode($encodedValue));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment