Yii Framework Forum: Facebook Yii Registration - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Facebook Yii Registration Rate Topic: -----

#1 User is offline   Ashutosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-December 11

Posted 10 January 2012 - 11:40 PM

I am implementing facebook registration in my Yii site.. I setup application. For registration, in one step, we need to decode facebook users data, send by facebook. Facebook provide the code for decoding information. I implement this code, but having error like:

" Fatal error: Call to undefined function base64_url_decode() in C:\wamp\www\cma\app\protected\controllers\SiteController.php on line 259 "

My code snippet is :

       public function actionFacebookLogin()
        {
            //error_reporting(E_ALL);
            //ini_set("display_errors", 1);
            
            $signed_request = $_POST['signed_request'];
            Yii::log("actionFacebookLogin called.....");
            //list($encoded_sig,$payload) = explode('.', $signed_request,2);
            
            list ($encoded_sig,$payload) = explode('.', $signed_request,2);
            
            Yii::log('in the list');
            //decode the data
            $sig =  base64_url_decode($encoded_sig);
            $data = json_decode(base64_url_decode($payload), true);
            
            if(strtoupper($data['algorithm'])!= 'HMAC-SHA256'){
                Yii::log('Unkonwon alogorithm.Expected HMAC-SHA256');
                //return null;
            }
           
        
            //check sig
            $expected_sig = hash_hmac('sha256', $payload, $secret,$raw=true);
            if($sig !== $expected_sig){
                Yii::log('Bad Signed JSON Signature');
                //return null;
            }
            //return $data;
            $this->render('facebookview',array('response'=>$data));
            
        }
        
          public function base64_url_decode($input)
            {
            return base64_decode(strtr($input, '-_', '+/'));
            }
        


I implement this code in my siteController...

Can anyone help to find what is wrong with the code..
Thanks in advance!
0

#2 User is offline   Mukesh 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 17-May 11
  • Location:India

Posted 11 January 2012 - 01:04 AM

View PostAshutosh, on 10 January 2012 - 11:40 PM, said:

I am implementing facebook registration in my Yii site.. I setup application. For registration, in one step, we need to decode facebook users data, send by facebook. Facebook provide the code for decoding information. I implement this code, but having error like:

" Fatal error: Call to undefined function base64_url_decode() in C:\wamp\www\cma\app\protected\controllers\SiteController.php on line 259 "

My code snippet is :

       public function actionFacebookLogin()
        {
            //error_reporting(E_ALL);
            //ini_set("display_errors", 1);
            
            $signed_request = $_POST['signed_request'];
            Yii::log("actionFacebookLogin called.....");
            //list($encoded_sig,$payload) = explode('.', $signed_request,2);
            
            list ($encoded_sig,$payload) = explode('.', $signed_request,2);
            
            Yii::log('in the list');
            //decode the data
            $sig =  base64_url_decode($encoded_sig);
            $data = json_decode(base64_url_decode($payload), true);
            
            if(strtoupper($data['algorithm'])!= 'HMAC-SHA256'){
                Yii::log('Unkonwon alogorithm.Expected HMAC-SHA256');
                //return null;
            }
           
        
            //check sig
            $expected_sig = hash_hmac('sha256', $payload, $secret,$raw=true);
            if($sig !== $expected_sig){
                Yii::log('Bad Signed JSON Signature');
                //return null;
            }
            //return $data;
            $this->render('facebookview',array('response'=>$data));
            
        }
        
          public function base64_url_decode($input)
            {
            return base64_decode(strtr($input, '-_', '+/'));
            }
        


I implement this code in my siteController...

Can anyone help to find what is wrong with the code..
Thanks in advance!


replace the function call to base64_url_decode($payload) with $this->base64_url_decode($payload)
0

#3 User is offline   Ashutosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-December 11

Posted 11 January 2012 - 01:23 AM

View PostMukesh, on 11 January 2012 - 01:04 AM, said:

replace the function call to base64_url_decode($payload) with $this->base64_url_decode($payload)


hey, thanks mukesh for help, but problem solved!

I placed, function base64_url_decode into model creating new util class and named as static function base64_url_decode. I called the function as util::base64_url_decode. :)

Anyways thanks for help!!! :D :)
0

#4 User is offline   Mukesh 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 17-May 11
  • Location:India

Posted 11 January 2012 - 01:29 AM

View PostAshutosh, on 11 January 2012 - 01:23 AM, said:

hey, thanks mukesh for help, but problem solved!

I placed, function base64_url_decode into model creating new util class and named as static function base64_url_decode. I called the function as util::base64_url_decode. :)

Anyways thanks for help!!! :D :)


Yes, it was more advisable to make it a helper function than limited to SiteController.
Also it's more advisable to use urldecode() function instead of strstr in your base64_url_decode() function.
0

#5 User is offline   Ashutosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-December 11

Posted 11 January 2012 - 02:58 AM

View PostMukesh, on 11 January 2012 - 01:29 AM, said:

Yes, it was more advisable to make it a helper function than limited to SiteController.
Also it's more advisable to use urldecode() function instead of strstr in your base64_url_decode() function.


Yuupp!! agreed!!! :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users