Validate Facebook Connect Cookie


/ Published in: PHP
Save to your folder(s)

Use this function to validate cookies set by Facebook Connect JS API


Copy this code and paste it in your HTML
  1. function _validateFBConnectCookie(){
  2. $params = array();
  3. $apiKey = Configure::read('Settings.fb_api_key');
  4.  
  5. foreach($_COOKIE as $key=>$value){
  6.  
  7. if( strpos($key, $apiKey.'_') === 0 ){
  8.  
  9. $paramName = substr($key, strlen($apiKey)+1);
  10.  
  11. $params[$paramName] = $value;
  12. }
  13. }
  14. ksort($params);
  15. $secret = Configure::read('Settings.fb_secret');
  16. $str = '';
  17. foreach($params as $key=>$value){
  18. $str .= $key.'='.$value;
  19. }
  20.  
  21. $calculatedSig = md5($str.$secret );
  22.  
  23. if(!empty($_COOKIE[$apiKey] ) && $_COOKIE[$apiKey] === $calculatedSig){
  24. return true;
  25. }
  26. return false;
  27. }

URL: validate_facebook_connect_cookie

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.