Reputation: 789
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!
Upvotes: 2
Views: 1514
Reputation: 789
Thanks for your help!!! But the 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
.
Upvotes: 1
Reputation: 258
If you're in a PHP class, and that base64_url_decode
is a public function, you should use it as $this->base64_url_decode($input)
, shouldn't you ?
In the example provided by Facebook Documentation it's only a simple function
that's why calling it without $this->
works.
Upvotes: 0
Reputation: 4708
base64_url_decode() is not a standard PHP function, you may need to define it like below:
function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_,');
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_,', '+/='));
}
taken from http://php.net/manual/de/function.base64-encode.php
Upvotes: 2