Posted By

ping_ch on 05/19/09


Tagged

cookie validation connect facebook facebookconnect


Versions (?)

Validate Facebook Connect Cookie


 / Published in: PHP
 

URL: validate_facebook_connect_cookie

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

  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. }

Report this snippet  

You need to login to post a comment.