Skip to content

Instantly share code, notes, and snippets.

@CEscorcio
Created May 18, 2015 15:55
Show Gist options
  • Save CEscorcio/8a3ea6a34a3d0b93978a to your computer and use it in GitHub Desktop.
Save CEscorcio/8a3ea6a34a3d0b93978a to your computer and use it in GitHub Desktop.
Facebook app Login
<?php
$app_id = "[YOUR APP ID]";
$canvas_page = "[YOUR APP URL]";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment