PHP Facebook SDK login unreliable -
i'm having strange behavior on script. using facebook php sdk create button link getloginurl() :
$loginurl = $facebook->getloginurl(array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => 'email', 'redirect_uri' => 'http://www.myurl.com') );
most of time works , can access user information using following bit of code
if(!isset($_session['front']['user_id']) || !is_numeric($_session['front']['user_id'])) { if (isset($_request['code'])) { try { $user_id = $facebook->getuser(); $basic = $facebook->api('/me?access_token=' . $access_token); if (is_array($basic) && is_numeric($user_id)) { $user = get_user_id_facebook($basic); $_session['front']['user_id'] = $user; $_session['front']['user_name'] = $basic['name']; $_session['front']['email'] = $basic['email']; $_session['front']['fbid'] = $basic['id']; return true; } else { return false; } } catch (exception $e) { return false; } } }
the problem cannot access user information... why unsteady? php version 5.3.2
your code unreliable you're executing code if code
exists in or post request. should doing checking if user logged in, e.g.
if ( $facebook->getuser() != 0 ) { // profile information } else { // log user in }
the code
parameter won't existing on page, it's returned facebook on successful login. not when user accesses page directly or via bookmark.
Comments
Post a Comment