Skip to content

Instantly share code, notes, and snippets.

@christophengelmayer
Forked from tiborsaas/like_gate.php
Created March 12, 2013 22:41
Show Gist options
  • Save christophengelmayer/5147760 to your computer and use it in GitHub Desktop.
Save christophengelmayer/5147760 to your computer and use it in GitHub Desktop.
<?php
/********************************************************
* Usage:
* - include this file in any document
* - use the following PHP tags to show / hide content:
*
* <?php if( LIKED ): ?>
* Welcome my friend
* <?php else: ?>
* Please like us
* <?php endif; ?>
*
*******************************************************/
$signed_request = $_REQUEST['signed_request'];
function parsePageSignedRequest()
{
if ( isset( $_REQUEST['signed_request'] ) )
{
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if( $signed_request = parsePageSignedRequest() )
{
if( $signed_request->page->liked )
{
define( 'LIKED', TRUE );
}
else
{
define( 'LIKED', FALSE );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment