Facebook Yii Registration

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)

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.

Yuupp!! agreed!!! :)