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

时间:2021-09-14 11:11:07

I'm trying to change session backend of Zend_Auth. But couldnt succeed it. In my bootstrap.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(
        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);

It was saving the values memcache successfully with no problem. I test it ;

它成功地保存了值memcache没有问题。我测试一下;

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

In other controller ;

在其他控制器;

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

It's ok, but I couldnt see Zend_Auth values in memcache.. But if I var_dump($_SESSION) I can see it like ;

没关系,但我在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 } } }

Here you can see my login method ;

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

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();
}

2 个解决方案

#1


0  

I do not know if this would be of any help but, Zend_auth automatically creates the storage thing to which you can access from anywhere using

我不知道这是否有任何帮助,但Zend_auth会自动创建您可以从任何地方访问的存储内容

$session = new Zend_Session_Namespace('Zend_Auth');
$session->storage->//here goes your property like user id password etc

Now if you use Zend_Auth it will use Zend_Auth_Storage_Session default value being "Zend_Auth" as the Zend_Session_Namespace. Now to change the namespace used modify the default value in Zend_Auth_Storage_Session else do it all manually if you want to cache this information or have it stored elsewhere you can always access it and move it to where you want.

现在,如果您使用Zend_Auth,它将使用Zend_Auth_Storage_Session默认值“Zend_Auth”作为Zend_Session_Namespace。现在要更改使用的命名空间,修改Zend_Auth_Storage_Session中的默认值,否则,如果要缓存此信息或将其存储在其他位置,请手动完成所有操作,您可以随时访问它并将其移动到您想要的位置。

Now i hoped I helped but I don't know anythng of memcache

现在我希望我能帮助,但我不知道任何memcache

#2


0  

I think it is simplest way and it will work out for you

我认为这是最简单的方式,它会为你工作

Dear Use user This Class For Zend Framework For Session.

亲爱的用户此类用于会话的Zend框架。

use Zend\Session\Container;

Then Do The Below procedure For Get Values From The Seesions.

然后执行以下过程从Seesions获取值。

    $user_session = new Container('user_login');
    $loginUser = $user_session->login_user['user_type'];

$user_session->login_user in this variable i store all the array of user related information like user type, user email, user id etc...then i get this session values on each page...

$ user_session-> login_user在这个变量中我存储了所有用户相关信息的数组,如用户类型,用户电子邮件,用户ID等...然后我在每个页面上获得此会话值...

#1


0  

I do not know if this would be of any help but, Zend_auth automatically creates the storage thing to which you can access from anywhere using

我不知道这是否有任何帮助,但Zend_auth会自动创建您可以从任何地方访问的存储内容

$session = new Zend_Session_Namespace('Zend_Auth');
$session->storage->//here goes your property like user id password etc

Now if you use Zend_Auth it will use Zend_Auth_Storage_Session default value being "Zend_Auth" as the Zend_Session_Namespace. Now to change the namespace used modify the default value in Zend_Auth_Storage_Session else do it all manually if you want to cache this information or have it stored elsewhere you can always access it and move it to where you want.

现在,如果您使用Zend_Auth,它将使用Zend_Auth_Storage_Session默认值“Zend_Auth”作为Zend_Session_Namespace。现在要更改使用的命名空间,修改Zend_Auth_Storage_Session中的默认值,否则,如果要缓存此信息或将其存储在其他位置,请手动完成所有操作,您可以随时访问它并将其移动到您想要的位置。

Now i hoped I helped but I don't know anythng of memcache

现在我希望我能帮助,但我不知道任何memcache

#2


0  

I think it is simplest way and it will work out for you

我认为这是最简单的方式,它会为你工作

Dear Use user This Class For Zend Framework For Session.

亲爱的用户此类用于会话的Zend框架。

use Zend\Session\Container;

Then Do The Below procedure For Get Values From The Seesions.

然后执行以下过程从Seesions获取值。

    $user_session = new Container('user_login');
    $loginUser = $user_session->login_user['user_type'];

$user_session->login_user in this variable i store all the array of user related information like user type, user email, user id etc...then i get this session values on each page...

$ user_session-> login_user在这个变量中我存储了所有用户相关信息的数组,如用户类型,用户电子邮件,用户ID等...然后我在每个页面上获得此会话值...