微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 将Zend_Auth存储后端$_SESSION更改为Memcached

我试图改变Zend_Auth的会话后端.但不能成功.
在我的bootstrap.PHP
$oBackend = new Zend_Cache_Backend_libmemcached(
        array(
            'servers' => $servers,'compression' => false
    ) );

    // configure caching frontend strategy
    $oFrontend = new Zend_Cache_Core(
        array(
            'caching' => true,'automatic_serialization' => true
        ) );

    // build a caching object
    $cache = Zend_Cache::factory( $oFrontend,$oBackend );

    $saveHandler = new \Application\Auth\Adapter\Memcached();
    $saveHandler->setCacher($cache);

    \Zend_Session::setSaveHandler($saveHandler);

它正在保存值memcache成功没有问题.我测试

$namespace = new Zend_Session_Namespace();
    $namespace->name = "Fatih";

在其他控制器

$ns = new Zend_Session_Namespace();
    var_dump($ns->name);

没关系,但是我不能在memcache中看到Zend_Auth的值.但是如果我的var_dump($_ SESSION)
我可以看到它像

["Zend_Auth"]=> array(1) { ["storage"]=> object(Application_Security_Auth_Storage)#66 (1) { ["_user":protected]=> object(Application_Security_Auth_User)#84 (4) { ["id":protected]=> object(MongoId)#87 (1) { ["$id"]=> string(24) "4fcca6b8c863c79d33000004" } ["username":protected]=> string(5) "admin" ["role":protected]=> string(5) "admin" ["fullname":protected]=> NULL } } }

在这里可以看到我的登录方式;

public function login($username,$password)
{
    if ($username == "" || $password == "")
        return false;

    $adapter = new \Application_Security_Auth_Adapter();

    $adapter->setIdentity($username);
    $adapter->setCredential($password);

    $auth = \Zend_Auth::getInstance();
    $result = $auth->authenticate($adapter);

    return $result->isValid();
}
我不知道这是否会有任何帮助,但Zend_auth会自动创建您可以从任何地方访问的存储空间
$session = new Zend_Session_Namespace('Zend_Auth');
$session->storage->//here goes your property like user id password etc

现在如果使用Zend_Auth,它将使用Zend_Auth_Storage_Session认值为“Zend_Auth”作为Zend_Session_Namespace.现在要更改所使用的命名空间,修改Zend_Auth_Storage_Session中的认值,否则,如果要缓存此信息或将其存储在其他位置,您可以手动将其全部移动,并将其移动到所需位置.

现在我希望我帮助,但我不知道任何内存缓存

原文地址:https://www.jb51.cc/php/131839.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐