Пример #1
0
 public function set(string $key, $value, int $expires = 0, bool $secure = false, string $domain = null, string $path = null, string $cryptKey = null)
 {
     if ($path == null) {
         $path = Runtime::$SETTINGS->getString("COOKIE_PATH", "/");
     }
     if ($domain == null) {
         $domain = Runtime::$SETTINGS->getString("COOKIE_DOMAIN", "");
     }
     /*
      * The key might already be hashed
      */
     if (!isset($this->mData[$key])) {
         $key = Crypt::hash($this->mPrefix . $key);
     }
     $this->mData[$key] = $value;
     if (!in_array(Runtime::$SYSTEM["REQUEST_CLIENT"], ["terminal", "crawler"])) {
         setcookie($key, $cryptKey !== null ? Crypt::encrypt(serialize($value), $cryptKey, true) : serialize($value), $expires, $path, $domain, $secure, true);
     }
 }
Пример #2
0
 public function setRaw(string $key, string $value, int $expires = 0, string $encKey = null) : bool
 {
     if ($encKey !== null) {
         $value = Crypt::encrypt($value, $encKey, true);
     }
     if ($expires > 0) {
         $expires = time() + $expires;
     }
     return $this->replaceCache($key, $value, $expires) > 0;
 }
Пример #3
0
 public function setRaw(string $key, string $value, int $expires = 0, string $encKey = null) : bool
 {
     $status = false;
     if ($encKey !== null) {
         $status = $this->mConnection->set($key, Crypt::encrypt($value, $encKey, false), $expires);
     } else {
         $status = $this->mConnection->set($key, $value, $expires);
     }
     return $status !== false;
 }
Пример #4
0
 /** @ignore */
 protected function write(string $key, string $value, int $expires = 0, string $encKey = null) : bool
 {
     $fileKey = sha1($key);
     // Key could contain non-filename characters
     $mtimeFile = $this->mPath . "mtime_{$fileKey}.cache";
     $cacheFile = $this->mPath . "{$fileKey}.cache";
     $status = false;
     if ($expires == 0 && is_file($mtimeFile)) {
         unlink($mtimeFile);
     } elseif ($expires > 0) {
         file_put_contents($mtimeFile, strval($expires));
     }
     if ($encKey !== null) {
         $status = file_put_contents($cacheFile, Crypt::encrypt($value, $encKey, false));
     } else {
         $status = file_put_contents($cacheFile, $value);
     }
     return $status !== false;
 }
Пример #5
0
 /** @ignore */
 public function writeBack()
 {
     if (!Runtime::hasLock("session")) {
         if ($this->mSessReady && !in_array(Runtime::$SYSTEM["REQUEST_CLIENT"], ["terminal", "crawler"])) {
             $data = serialize($this->mData);
             if (Runtime::$SETTINGS->getBoolean("SESSION_ENCRYPT_DATA")) {
                 $cryptKey = Runtime::$SETTINGS->getString("SECURITY_PASSWD");
                 if (!empty($cryptKey)) {
                     $data = Crypt::encrypt($data, $cryptKey, true);
                 }
             }
             $this->mSessHandler->write($data);
         }
         $this->mSessReady = false;
     } else {
         Runtime::addLockCallback("session", [$this, "writeBack"]);
     }
 }