stanley-king hace 9 años
padre
commit
09d7de1813
Se han modificado 2 ficheros con 14 adiciones y 7 borrados
  1. 5 1
      helper/http_header.php
  2. 9 6
      helper/session.php

+ 5 - 1
helper/http_header.php

@@ -320,11 +320,13 @@ function init_cookie($cookie)
     $regxp = '/([^=]+=[^;]*)[;]?/i';
     $val = preg_match_all($regxp,$cookie,$match);
 
+    if($val == false) return false;
+
     foreach($_COOKIE as $key => $val) {
         unset($_COOKIE[$key]);
     }
 
-    if($val == 2)
+    if(count($match) == 2)
     {
         foreach($match[1] as $val)
         {
@@ -339,6 +341,8 @@ function init_cookie($cookie)
             }
         }
     }
+
+    return true;
 }
 
 function fcgi_setcookie($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httponly = null)

+ 9 - 6
helper/session.php

@@ -18,6 +18,7 @@ class session
     const type = 'redis';
     const save_path = 'tcp://127.0.0.1:6379';
     const prefix = 'PHPREDIS_SESSION';
+    const session_name = 'PHPSESSID';
 
     static public function instance()
     {
@@ -43,8 +44,8 @@ class session
             array(&$this,'onRead'),
             array(&$this,'onWrite'),
             array(&$this,'onDestroy'),
-            array(&$this,'onGc'),
-            array(&$this,'onCreateSid'));
+            array(&$this,'onGc'));
+            //array(&$this,'onCreateSid'));
     }
 
     public function start()
@@ -60,8 +61,7 @@ class session
             session_write_close();
         }
 
-        foreach($_SESSION as $key=>$value)
-        {
+        foreach($_SESSION as $key=>$value) {
             unset($_SESSION[$key]);
         }
     }
@@ -77,10 +77,13 @@ class session
     public function onRead($sid)
     {
         $ret = $this->redis->hGet(self::prefix,$sid);
-        if(empty($ret)) {
+        if(empty($ret))
+        {
+            if(empty($_COOKIE[self::session_name]) || $_COOKIE[self::session_name] != $sid) {
+                fcgi_setcookie("PHPSESSID","{$sid}",time() + self::sid_expire);
+            }
             return '';
         } else {
-            fcgi_setcookie("PHPSESSID","{$sid}",time() + 60);
             return $ret[0];
         }
     }