当前位置: 动力学知识库 > 问答 > 编程问答 >

reconciling Facebook PHP SDK with zend framework

问题描述:

so I'm using the Facebook PHP SDK for authenticating my user....

and I'm trying to logout my user using the destroySession() method in base_facebook.php

These are some relevant excerpts in the PHP SDK's base_facebook.php: https://github.com/facebook/php-sdk/blob/master/src/base_facebook.php

 public function destroySession() {

$this->setAccessToken(null);

$this->user = 0;

$this->clearAllPersistentData();

}

protected function clearAllPersistentData() {

foreach (self::$kSupportedKeys as $key) {

$this->clearPersistentData($key);

}

}

protected function clearPersistentData($key) {

if (!in_array($key, self::$kSupportedKeys)) {

self::errorLog('Unsupported key passed to clearPersistentData.');

return;

}

$session_var_name = $this->constructSessionVariableName($key);

unset($_SESSION[$session_var_name]);

}

but everytime I try to do so, Zend Framework would complain

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()'

Zend_Session_Exception: session has already been started by session.auto-start or session_start()

How do I go about clearing my facebook session without triggering all these errors?

网友答案:

The prerequisite for using Zend_Session is the session must not be initiated yet. Facebook initiates it. As a solution, call session_write_close() before using Zend_Session.

Alternatively, call session_destroy() to logout the facebook user. It destroys all of the data associated with the current session.

网友答案:

In order to make it work with Zend_Session, I modified the facebook.php source code and replace

    session_start()

by

    $this->session = new Zend_Session_Namespace();
    $this->session->fb = array();

Then replace all occurences of

    $_SESSION"

by

    $this->session->fb
分享给朋友:
您可能感兴趣的文章:
随机阅读: