8
我使用最新FB PHP SDK中的非JS示例。它工作正常,除非用戶關閉瀏覽器並重新打開頁面。他們必須再次點擊FB登錄鏈接。Facebook PHP SDK,如何保持持久登錄
我是在假設$ facebook-> getUser()處理cookie。
代碼:
require 'sdk/facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'test',
'secret' => 'test',
'cookie' => true));
// Get User ID
$user = $facebook->getUser();
// 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.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>
是否有額外的步驟,我在這裏失蹤?我發現這裏的代碼從FB cookies中提取數據:facebook auto re-login from cookie php
顯然這不再需要SDK了嗎?