2009-09-06 18 views
16

PHP ve Zend Framework kullanarak bir Connect uygulaması oluşturmaya çalışıyorum. Ayrıca bir Zend_Auth tabanlı kullanıcı kimlik doğrulama sistemim var. Şimdi, Facebook’u kullanarak oturum açabiliyorum ancak oturum açma çalışmıyor.Facebook ile kullanıcılar nasıl bağlanılır? PHP ve Zend'de bağlanın mı?

Tüm Facebook giriş bilgilerini kaldırmanın yanı sıra Zend_Auth kimliğini de temizlemem gerekiyor. Bunu yapmanın en iyi yolu ne olurdu?

ben onlardan Zend_Auth::getInstance()->clearIdentity()

Yok çalışmıyor gibi görünüyor çağıran sonra birlikte ve ayrıca facebook_client->logout($next)facebook_client->expire_session() ve facebook_client->clear_cookie_state(); çalıştı.

cevap

20

Önce javascript istemcisi oturumunu önce numaralı telefondan aramanız ve sonra bunları php logut komut dosyasına göndermeniz gerekir. Yani, çağrı .js:

FB.Connect.logoutAndRedirect("/path/to/zend/logout/controller"); 

Sen * Sen çıkış script yerde yönlendirileceksiniz.BREAKDaha bu siteye ve facebook üzerinden giriş yaptığını" diyor Kalıcı açılan görürsünüz:

try 
{ 
    $facebook->expire_session(); 
} 
catch (FacebookRestClientException $e) 
{ 
    //you'll want to catch this 
    //it fails all the time 
} 

genellikle de güvende olmak için, PHP çıkış komut bu işlevi çağırır:

/** 
* Remove the local Facebook cookies that get set manually 
* 
* @return void 
*/ 
protected function _killFacebookCookies() 
{ 
    // get your api key 
    $apiKey = $this->getConfig()->getApiKey(); 
    // get name of the cookie 
    $cookie = $this->getConfig()->getCookieName(); 

    $cookies = array('user', 'session_key', 'expires', 'ss'); 
    foreach ($cookies as $name) 
    { 
     setcookie($apiKey . '_' . $name, false, time() - 3600); 
     unset($_COOKIE[$apiKey . '_' . $name]); 
    } 

    setcookie($apiKey, false, time() - 3600); 
    unset($_COOKIE[$apiKey]);  
} 
+0

Teşekkürler! İşe yarıyor! :) – Abhinav

+0

yeap, işe yarıyor! _killFacebookCookies() ek işlevi olmadan test edilmiş, iyi çalışıyor. – Alex

0

Sen facebook kullanıcı çıkış ve bunun gibi bir PHP kodu ile web sitesi sayfasına yönlendirecek edebilirsiniz:

header ("Konum:"). $ Facebook-> getLogoutUrl (dizi ('sonraki' => "http://yourwebsite.com/redirectAfterFacebookLogout.php")));

0

(YENİ FACEBOOK SDK) Bana göre getconfig() işe yaramazdı. Baz_facebook.php dosyasındaki yeni işlevleri bulup bu kod kodunu ekledim. Ardından çağrı dosyanızda arayın. Yapmadan önce $ facebook-> destroySession();

public function _killFacebookCookies() 
    { 
     // get your api key 
     $apiKey = $this->getAppId(); 
     // get name of the cookie 
     $cookie = $this->getSignedRequestCookieName(); 

     $cookies = array('user', 'session_key', 'expires', 'ss'); 
     foreach ($cookies as $name) 
     { 
      setcookie($apiKey . '_' . $name, false, time() - 3600); 
      unset($_COOKIE[$apiKey . '_' . $name]); 
     } 

     setcookie($apiKey, false, time() - 3600); 
     unset($_COOKIE[$apiKey]);   
    } 
İlgili konular