dongqi3533 2013-11-26 23:05
浏览 54

我从Facebook退出后仍然记录了我的Facebook应用程序

I have a website where you can login with Facebook. I login to my website, all well and good. But after going on www.facebook.com and log out, when I get back on the website and give refresh, the app works perfectly as if I logged in to Facebook. I tried all sorts of conditions, such as:

$user_profile = $facebook->api('/me');
if($user_profile !== $_SESSION['id']) {
header( 'Location: logout.php' ) ;
}

but nothing works, how can I send it to the logout page if the user is not logged on facebook?

Here is my code:

<?php
    // Application Configurations
    $app_id     = "xxxxxxxxxxxxxxxx";
    $app_secret = "xxxxxxxxxxxxxxx";
    $site_url   = "xxxxxxxxxxxxxxx";

    try {
        include_once "src/facebook.php";
    }
    catch(Exception $e){
        error_log($e);
    }

    // Create our application instance
    $facebook = new Facebook(array(
        'appId'     => $app_id,
        'secret'    => $app_secret,
        'cookie' => true,
        ));

    // Get User ID
    $user = $facebook->getUser();
    $user_profile = null;
    // Get the current access token 
    // We may or may not have this data based 
    // on whether the user is logged in.
    // If we have a $user id here, it means we know 
    // the user is logged into
    // Facebook, but we don’t know if the access token is valid. An access
    // token is invalid if the user logged out of Facebook.
    // print_r($user);

    if ($session) {
    echo "este";
    } else {
    echo "nu este";
    }
    if(!isset($_SESSION['id']))
    {
        if($user){
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');

            // Get logout URL
            $logoutUrl = $facebook->getLogoutUrl();

            try{
                //Connecting to the database. You would need to make the required changes in the common.php file
                //In the common.php file you would need to add your Hostname, username, password and database name!
                mysqlc();

                $id = $user_profile['id'];
                $name = $user_profile['name'];
                $email = $user_profile['email'];
                $gender = $user_profile['gender'];
                $bio = $user_profile['bio'];

                $query = sprintf("SELECT * FROM newmember WHERE id = %s", $id);
                $results = mysql_query($query) or die('tubRandom - Query failed: ' . mysql_error() . "<br />
$sql");

                if(mysql_num_rows($results) == 0)
                {
                    $query_two = sprintf("INSERT INTO newmember values(%s,%s,%s,%s,%s,'yes')", $id, $name, $email, $gender, $bio);
                    $insert_query_two = mysql_query($query_two) or die('tubRandom - Query failed: ' . mysql_error() . "<br />
$sql");

                    $_SESSION['id'] = $user_profile['id'];
                } else {
                    $rows = mysql_fetch_array($results);
                    $_SESSION['id'] = $user_profile['id'];
                }
            }
            catch(FacebookApiException $e){
                    error_log($e);
                    $user = NULL;
            }

        } else {
            // Get login URL
            $loginUrl = $facebook->getLoginUrl(array(
                'scope'         => 'read_stream, publish_stream, email, user_about_me, user_website, user_work_history, user_relationships, user_religion_politics, user_relationships, user_likes, user_location, user_relationship_details, user_hometown, user_education_history',
                'redirect_uri'  => $site_url,
            ));
        }

    } else {
        $user_profile = $facebook->api('/me');

            echo $user_profile['name'] . $user_profile . $user_profile['id'] . $_SESSION['id'];
            //header( 'Location: logout.php' ) ;

    }
?>

Sorry if it is a dummy question, I am a girl. :D

  • 写回答

2条回答 默认 最新

  • dtnwm4807 2013-11-27 00:12
    关注

    Well, first of all I don't see why you have to make a note of your gender. Anyway, have a look at the FB.getLoginStatus function.

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法