I'm using the php facebook class and put a login button on my page with $f->getLoginUrl(), the problem is this button does not work at first time I click on it. It does what it's supposed to and returns to my site but the $f->getUser() is empty. Strange thing is when I click the button the second time then it works flawlessly.
$facebook = new Facebook(array( 'appId' => '25317735807xxxx', 'secret' => '37e5dd05657f2cc2a1bdc9974985xxxx', 'redirURL' => 'http://mysite.com/', )); $fb_login = '<a href="' . $facebook->getLoginUrl() . '" class="fb-login-button"><img src="img/fb-login-button.png" border="0" /></a>'; $fb_user = $facebook->getUser(); $user_level = 4; if($page_access[$glob['pag']]['session']) { session_start(); } if ($_SESSION[U_ID]) { $user_level = $_SESSION['access_level']; require_once("classes/cls_auth.php"); $auth = new auth(); $show_connect_alert = $auth->check_connection(); if($glob['pag'] == 'register' && $_SESSION[U_ID]) { $glob['pag'] = 'profile'; } } else { //check if fb session exists if ($fb_user) { try { $db = new mysql_db(); $db->query("SELECT email, password FROM member WHERE fb_id = $fb_user"); if ($db->move_next()) { $glob['email'] = $db->f('email'); $glob['password'] = $db->f('password'); require_once("classes/cls_auth.php"); $auth = new auth(); $auth->login($glob); } else { $user_profile = $facebook->api('/me'); $glob['pag'] = "fboptions"; } } catch (FacebookApiException $e) { $glob['fb-error'] = $e; unset($fb_user); $user_level = 4; } } else { // check login cookie if(isset($_COOKIE['stagescan'])) { list($arr['email'], $arr['password']) = explode(",", $_COOKIE['stagescan']); require_once("classes/cls_auth.php"); $auth = new auth(); if(!$auth->login($arr)) { setcookie('stagescan', "", time()-3600, "http://mysite.com/"); } else { $glob['debug'] = "User logged in from cookie"; } } else { $user_level = 4; } } }