示例#1
0
 /**
  * Writes self to cookie
  * @return void
  */
 public function write()
 {
     try {
         $values = $this->options;
         $valuesToSerialize = array();
         foreach ($values as $subName => $subOptions) {
             foreach ($subOptions as $elementName => $value) {
                 if ($value != null) {
                     $valuesToSerialize[$subName][$elementName] = $value;
                 }
             }
         }
         $values = serialize($valuesToSerialize);
         $crypted = Dfi_Crypt_MCrypt::encode($values);
         $base64 = base64_encode($crypted);
         $response = Zend_Controller_Front::getInstance()->getResponse();
         $response->setHeader('Set-Cookie', self::COOKIE_SELECTOR . ' = ' . $base64 . '; expires= ' . date('r', time() + 60 * 20) . ';path = /; httponly');
     } catch (Exception $e) {
     }
 }
示例#2
0
文件: Cookie.php 项目: dafik/dfi
 /**
  * Writes $contents to storage
  *
  * @param  mixed $contents
  * @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
  * @return void
  */
 public function write($contents)
 {
     $user = $contents;
     try {
         if (null === $user) {
             if ($this->user) {
                 $user = $this->user;
             } else {
                 return;
             }
         }
         if ($user) {
             $this->userId = $user->getPrimaryKey();
             if (!headers_sent()) {
                 $response = Zend_Controller_Front::getInstance()->getResponse();
                 $date = new DateTime();
                 $date->modify('+1200 seconds');
                 $response->setHeader('Set-Cookie', '_u = ' . base64_encode(Dfi_Crypt_MCrypt::encode($user->getPrimaryKey() . '-' . time())) . '; Expires=' . $date->format(DATE_COOKIE) . '; path = /');
                 $this->headersSent = true;
             } else {
                 headers_sent($file, $line);
                 throw new Exception('headers have been sent, file: ' . $file . ' line: ' . $line);
             }
         }
     } catch (Exception $e) {
         throw new Zend_Auth_Storage_Exception($e->getMessage());
     }
 }