简体   繁体   中英

how to log user out with facebook api

I am trying to check if a User sessions exist with facebook api.

If someone is logged in I want to show a logout link,

If they are not logged in I want to show a login link.

No matter what it is showing a logout link. I think maybe because the call is not logging the user out?????

Also what is the best practice to verify a session for restricted pages? Should I follow the same concept I am using?

 <?php if ($user): ?> // nothing else { redirect to login page?

Here is my code.

  <?php if ($user): ?>
      <dd><a href="<?php echo $logoutUrl; ?>"><span class="fui-facebook"> </span>Logout</a>
        </dd>
    <?php else: ?>
                <dd><a href="<?php echo $loginUrl; ?>"><span class="fui-facebook"> </span>Sign In with Facebook</a>
                    </dd> 
    <?php endif ?>
            </dl> 
          </div>
        </div>
    </nav>

Use this code to log out with facebook api

FB.logout(function(response) { // user is now logged out });

If you need more help then visit https://developers.facebook.com/docs/reference/javascript/FB.logout/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM