dongwuwei0718 2009-10-09 22:00
浏览 92
已采纳

无法登出Facebook连接站点并销毁会话

I can't seem to get a facebook connect app that I am building to log the user out (sorry no url as it's still in dev). Each time the user clicks a link with the class "logout" the following JS runs which seems to work and even shows the FB modal stating the user has been logged out.

$(document).ready(function(){
    $('.logout').click(function(){
        //Kill facebook Session
        FB.Connect.logout(function() {
            window.location = $('.logout').attr("href");
        });
    });
});

Upon reaching the callback above, the JS sends the user to the logout page where PHP again forces the removal of a custom session and insures that the FB session was removed. Then the user is sent back to the page they were on when they clicked the "logout" link.

//Remove our site session
Auth::logout();



/* FAIL
//Send user to FB logout page and then back here
$logout_url = $this->fb->get_logout_url( site_url( $return_to ? base64_url_decode($return_to) : '' ) );

// Clear any stored state
$this->fb->clear_cookie_state();

exit(header("Location: ". $logout_url));
*/



//FAIL
//$this->fb->logout( site_url( $return_to ? base64_url_decode($return_to) : '' ) );


//FAIL
//Remove user (is this needed..?)
//$this->fb->set_user(NULL, NULL);


//Remove the FB session cookies (in case the JS didn't)
$this->fb->clear_cookie_state();


// Redirect to privious page
redirect( ( $return_to ? base64_url_decode($return_to) : '') );

However, this whole process results in the user being right back where they were and still logged in. A second click on the link seems to do the trick and remove the session though. I have monitored firebug (w/firecookie) and the PHP logout page reports deleting the FB session cookies - yet the next page loaded seems to still use them?!

If anyone knows how to completely DESTROY ALL FACEBOOKS ahem... sessions then please speak up.

:EDIT: I have even tried to manually remove all cookies on the logout page and it still fails

if( $_COOKIE ) {

    foreach( $_COOKIE as $name => $value ) {

        //Get the current cookie config
        $params = session_get_cookie_params();

        // Delete the cookie from globals
        unset($_COOKIE[$name]);

        //Delete the cookie on the user_agent
        setcookie($name, '', time()-43200, $params['path'], '', $params['secure']);
    }
}
  • 写回答

3条回答 默认 最新

  • duanjuda5789 2009-11-09 16:41
    关注

    My guess is that because you are starting the Facebook api classes it reads the session and sets all the cookies again your Javascript call just cleared.

    The php facebook lib and the FB js lib both use the same cookienames. (so you can login through javascript and the php lib will be logged in as well).

    There is a specific function for a log out and going to a URL by the way:

    FB.Connect.LogoutAndRedirect(url); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址