My Octopress Blog

A blogging framework for hackers.

Validate Facebook Layout

function validate_facebook_session($args, $app_secret) {
  $payload = '';
  ksort($args);
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  $hash_in = $payload . $app_secret;
  $sig = $args['sig'];
  if (md5($hash_in) != $sig) {
    return null;
  }
  return $args;
}