加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 16:38:13 所属栏目:PHP教程 来源:网络整理
导读:我试图改变Zend_Auth的会话后端.但不能成功. 在我的bootstrap.php $oBackend = new Zend_Cache_Backend_Libmemcached( array( 'servers' = $servers,'compression' = false ) ); // configure caching frontend strategy $oFrontend = new Zend_Cache_Core(
我试图改变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 ApplicationAuthAdapterMemcached();
    $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中的默认值,否则,如果要缓存此信息或将其存储在其他位置,您可以手动将其全部移动,并将其移动到所需位置.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读