ds78662302 2014-08-26 08:25
浏览 81

Facebook App登录记住会话

I am using the following code in my PHP to login with Facebook App and each time I close the browser and re-open it, I need to re-login again. Is there anyway I can remember the login session so that I will be logged in until I hit logout.

Thanks

Code:

$facebook = new Facebook(array(
        'appId'     =>  $appID,
        'secret'    => $appSecret,
        ));
//get the user facebook id      
$user = $facebook->getUser();

if($user){

    try{
        //get the facebook user profile data
        $user_profile = $facebook->api('/me');
        $params = array('next' => $base_url.'logout.php');
        //logout url
        $logout =$facebook->getLogoutUrl($params);
        $_SESSION['User']=$user_profile;
        $_SESSION['logout']=$logout;
    }catch(FacebookApiException $e){
        error_log($e);
        $user = NULL;
    }       
}

if(empty($user)){
//login url 
$loginurl = $facebook->getLoginUrl(array(
                'scope'         => 'email,read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
                'redirect_uri'  => $base_url.'login.php',
                'display'=>'popup'
                ));


header('Location: '.$loginurl);
  • 写回答

2条回答 默认 最新

  • duanjiao2978 2014-08-26 08:30
    关注

    I think facebook uses cookies to keep your session open. I know this sounds stupid, but do you enable the "remember me" checkbox on login ?

    If you do, your PHP should have $user with getUser(). I think.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line