Exemple #1
0
 /**
  * Defines a cookie to be sent along with the rest of the HTTP headers.
  *
  * @link http://www.php.net/manual/en/function.setcookie.php
  *
  * @param  string  $name     The name of the cookie.
  * @param  string  $value    (optional) The value of the cookie.
  * @param  integer $expire   (optional) The time the cookie expires. This is a Unix timestamp
  * @param  string  $path     (optional) The path on the server in which the cookie will be available on.
  * @param  string  $domain   (optional) The domain that the cookie is available to.
  * @param  boolean $secure   (optional) Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client.
  * @param  boolean $httponly (optional) When TRUE the cookie will be made accessible only through the HTTP protocol.
  * @return boolean
  */
 public static final function setcookie($name, $value, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false)
 {
     $value = rawurlencode($value);
     return Cookie::setrawcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
 }
Exemple #2
0
 /**
  * Start new or resume existing session
  *
  * @link http://www.php.net/manual/en/function.session-start.php
  */
 public static final function session_start()
 {
     if (self::$started) {
         trigger_error('Session already started', E_USER_WARNING);
     }
     self::$started = true;
     if (isset($_COOKIE[session_name()])) {
         self::$id = $_COOKIE[session_name()];
     } else {
         self::$id = uniqid();
         $config = self::session_get_cookie_params();
         Cookie::setcookie(session_name(), self::$id, $config['lifetime'], $config['path'], $config['domain'], $config['secure'], $config['httponly']);
     }
     if (!($savePath = session_save_path())) {
         $savePath = sys_get_temp_dir();
     }
     if (!is_dir($savePath)) {
         mkdir($savePath, 0777);
     }
     self::$file = sprintf('%s/sess_%s', $savePath, self::$id);
     if (self::$handler) {
         self::$handler->open($savePath, session_name());
         self::$handler->read(self::$id);
     }
     if (file_exists(self::$file)) {
         $data = file_get_contents(self::$file);
         session_decode($data);
     }
     return true;
 }