Coding Help!

pasenseoso

Power Member
Joined
Aug 19, 2011
Messages
765
Reaction score
141
Hi fellow BH,

I am scrambling to get this code working but I miserable failed. It should suppose to redirect to either 2 pages. Pages for the likers and non likers. However, even if a user has liked a particular page, still there is no redirection or whatsoever. Can anyone help me fix this code? Its actually an FB fangate.

Code:
<?php
  $app_secret="xxxxxxxxxxxxx";
  $data = parse_signed_request($_REQUEST['signed_request'], $app_secret);
  $page_data=$data['page'];


  function parse_signed_request($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);


    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);


    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
      error_log('Unknown algorithm. Expected HMAC-SHA256');
      return null;
    }
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
      error_log('Bad Signed JSON signature!');
      return null;
    }


    return $data;
  }
  function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
  }


  if($page_data['liked'] == "1"){


    // Fan Content


  }else{


    // No-Fan Content


  }
?>
 
Hi fellow BH,

I am scrambling to get this code working but I miserable failed. It should suppose to redirect to either 2 pages. Pages for the likers and non likers. However, even if a user has liked a particular page, still there is no redirection or whatsoever. Can anyone help me fix this code? Its actually an FB fangate.

Code:
<?php
  $app_secret="xxxxxxxxxxxxx";
  $data = parse_signed_request($_REQUEST['signed_request'], $app_secret);
  $page_data=$data['page'];


  function parse_signed_request($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);


    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);


    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
      error_log('Unknown algorithm. Expected HMAC-SHA256');
      return null;
    }
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
      error_log('Bad Signed JSON signature!');
      return null;
    }


    return $data;
  }
  function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
  }


  if($page_data['liked'] == "1"){


    // Fan Content


  }else{


    // No-Fan Content


  }
?>
echo the variable to see what it outputs.
 
I have tried it, yet still it does not redirect (I actually used redirection instead of showing content). Maybe there is a new script for fb fan gating (for websites and not page tab)?
 
there are lots of fb scripts online which can help you in redirect the non fan user and fan user
& are you sure you are putting right APP_SEcret
 
Yup I did put the right app secret. Yes it does work to filter non page likers.. But even if you hit the like button and refresh the page, nothing happens...
 
Back
Top