【问题标题】:in zend, how to check by ID that a session exists?在zend中,如何通过ID检查会话是否存在?
【发布时间】:2011-02-28 12:15:43
【问题描述】:

我正在使用带有 xml 数据的谷歌地图, 谷歌地图的工作方式是它调用我的服务器来获取 xml(我必须向它传递一个 url,我不能将 xml 传递给谷歌),

因为我的所有页面都受用户/密码保护, 我需要为谷歌地图实现某种身份验证,所以我正在考虑将当前用户会话 ID(以某种方式加密)传递给它,以便当谷歌调用我的脚本时,我可以检查具有该 ID 的会话是否存在,因此谷歌代表该用户给我打电话

【问题讨论】:

  • 你是如何存储你的会话的?
  • 不知道,zend的默认存储方式

标签: php zend-framework session google-maps


【解决方案1】:

我最终使用自己的表来保存会话,然后对其执行查询

在 bootstrap.php 中

protected function _initSession()
    {

         $this->bootstrap('cache')
        $config = array(
            'name'              => 'session', //table name as per Zend_Db_Table
            'primary'           => array(
                'session_id',   //the sessionID given by PHP
                'save_path',    //session.save_path
                'name',         //session name
                //'cols' => array('session_id', 'save_path', 'name', 'modified', 'lifetime', 'session_data')
            ),
            'primaryAssignment' => array(
                //you must tell the save handler which columns you
                //are using as the primary key. ORDER IS IMPORTANT
                'sessionId', //first column of the primary key is of the sessionID
                'sessionSavePath', //second column of the primary key is the save path
                'sessionName', //third column of the primary key is the session name
            ),
            'modifiedColumn'    => 'modified',     //time the session should expire
            'dataColumn'        => 'session_data', //serialized data
            'lifetimeColumn'    => 'lifetime',     //end of life for a specific record
            'user_id' => 'user_id'
        );
        //Tell Zend_Session to use your Save Handler
        $savehandler = new Zend_Session_SaveHandler_DbTable($config);


        //http://framework.zend.com/wiki/display/ZFPROP/Zend_Session_SaveHandler_DbTable
        //cookie persist for 30 min
        $config = Zend_Registry::get('config');


        $seconds = $config->session->seconds_life;
        //Zend_Session::rememberMe($seconds = ($config->session->seconds_life));
        //make the session persist for 30 min
        $savehandler->setLifetime($seconds)
            ->setOverrideLifetime(true);

        Zend_Session::setSaveHandler($savehandler);

        Zend_Session::start();
    }

【讨论】:

    【解决方案2】:

    session_id() 会给你当前请求的session id。您可以尝试将此作为 cookie 发送给 Google,请记住,要使其正常工作,Google 必须接受您的 cookie。如果没有,那么您将不得不找到其他方法

    【讨论】:

    • 你的意思是尝试从我的网站窃取 cookie 并自己将其注入谷歌 :D,嗯,我不知道,从长远来看不会激发信任
    • session_id 是公开的 - 你不会放弃任何东西。
    【解决方案3】:

    我建议使用 Zend Session 类的方法。

    $sessionId = Zend_Session::getId();
    

    【讨论】:

    • 这行不通,因为 google 会自动获得一个新的会话 id,因为 zend 甚至会为未通过身份验证的用户分配一个
    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 2011-02-18
    • 2012-10-18
    • 2016-11-20
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多