2011-02-28 73 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