2011-02-28 75 views
0

我使用谷歌地图使用XML数据, 谷歌地图的工作方式是,它调用我的服务器来获取XML(我要传递一个网址,我无法通过XML来谷歌),在zend中,如何通过ID检查会话是否存在?

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

+1

你是如何存储你的会话

执行查询就可以了? – kjy112 2011-02-28 13:31:38

+0

不知道,默认的方式zend存储他们 – max4ever 2011-03-02 16:55:07

回答

0

最后我用我自己的表来保存会话,然后在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(); 
    } 
0

session_id()会给你当前请求的session id。您可以尝试将此信息作为cookie发送给Google,请记住,为此,Google必须接受您的Cookie。如果它不,那么你将不得不寻找不同的方式

+0

你的意思是尝试从我的网站偷一个cookie并注入到谷歌bymyself:D,嗯,我不知道,不会激发长期的信任 – max4ever 2011-03-02 16:56:25

+0

'session_id'是公开的 - 你不会泄露任何东西。 – 2011-03-02 22:23:28

0

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

$sessionId = Zend_Session::getId(); 
+0

这将无法正常工作,因为谷歌自动获得一个新的会话ID,因为甚至zend分配一个用户没有身份验证 – max4ever 2011-03-02 16:55:22