简体   繁体   中英

Zend Framework 2: Session SaveHandler - save IP Address

I am using a custom Session\\SaveHandler with the following DbTableGatewayOptions:

        $gwOpts = new DbTableGatewayOptions();
        $gwOpts->setDataColumn('data');
        $gwOpts->setIdColumn('id');
        $gwOpts->setLifetimeColumn('lifetime');
        $gwOpts->setModifiedColumn('modified');
        $gwOpts->setNameColumn('name');

        $saveHandler = new DbTableGateway($this->tblGW, $gwOpts);
        $sessionManager = new SessionManager();
        if ($this->sessionConfig) {
            $sessionConfig = new \Zend\Session\Config\SessionConfig();
            $sessionConfig->setOptions($this->sessionConfig);
            $sessionManager->setConfig($sessionConfig);
        }
        $sessionManager->setSaveHandler($saveHandler);
        Container::setDefaultManager($sessionManager);
        $sessionManager->start();

What's the best way to add 2 additional fields for user_agent and client_ip ? Is that even possible?

我相信你可以使用例如$_SERVER['REMOTE_ADDR'];添加ip作为会话变量$_SERVER['REMOTE_ADDR'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM