Skip to content

Instantly share code, notes, and snippets.

@mpezzi
Created August 23, 2012 18:03
Show Gist options
  • Save mpezzi/3439641 to your computer and use it in GitHub Desktop.
Save mpezzi/3439641 to your computer and use it in GitHub Desktop.
Facebook Application Redirect Script
<?php
// Configuration.
$conf = array(
'domain' => '',
);
if ( isset($_REQUEST['signed_request']) ) {
// Parse signed request.
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$request = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
// Redirect on user using Facebook Locale.
if ( isset($request['user']['locale']) ) {
// Prevent caching this page.
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Choose appropriate language.
switch ( $request['user']['locale'] ) {
case 'fr_CA':
case 'fr_FR':
$lang = 'fr';
break;
default:
$lang = '';
break;
}
// Redirect visitor to proper language page.
header('Location: ' . $conf['domain'] . '/' . $lang . '?signed_request=' . $_REQUEST['signed_request']);
}
}
// Fallback if no signed request is available.
else {
header('Location: ' . $conf['domain'] . '/');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment