コード例 #1
0
ファイル: Cookie.php プロジェクト: ph-7/cookiesession
 /**
  * Set a PHP Cookie.
  *
  * @param mixed (array | string) $mName Name of the cookie.
  * @param string $sValue value of the cookie, Optional if the cookie data is in a array.
  * @param int $iTime The time the cookie expires. This is a Unix timestamp.
  * @param bool $bSecure If TRUE cookie will only be sent over a secure HTTPS connection from the client.
  * @return void
  */
 public function set($mName, string $sValue = null, int $iTime = null, bool $bSecure = null)
 {
     $iTime = time() + ((int) (!empty($iTime)) ? $iTime : $this->getExpiration());
     $bSecure = !empty($bSecure) && is_bool($bSecure) ? $bSecure : $this->getIsSsl();
     if (is_array($mName)) {
         foreach ($mName as $sN => $sV) {
             $this->set($sN, $sV, $iTime, $bSecure);
             // Recursive method
         }
     } else {
         $sCookieName = $this->getPrefix() . $mName;
         /* Check if we are not in localhost mode, otherwise may not work. */
         if (!Various::isLocalHost()) {
             setcookie($sCookieName, $sValue, $iTime, $this->getPath(), $this->getDomain(), $bSecure, true);
         } else {
             setcookie($sCookieName, $sValue, $iTime, '/');
         }
     }
 }
コード例 #2
0
ファイル: Session.php プロジェクト: ph-7/cookiesession
 /**
  * Constructor to initialize PHP's session.
  *
  * @param boolean $bDisableSessCache Disable PHP's session cache. Default FALSE
  */
 public function __construct(bool $bDisableSessCache = false)
 {
     if ($bDisableSessCache) {
         session_cache_limiter(false);
     }
     session_name($this->getCookieName());
     /**
      * In localhost mode, security session_set_cookie_params causing problems in the sessions, so we disable this if we are in localhost mode.
      * Otherwise if we are in production mode, we activate this.
      */
     if (!Various::isLocalHost()) {
         $iTime = (int) $this->getExpiration();
         session_set_cookie_params($iTime, $this->getPath(), $this->getDomain(), $this->getIsSsl(), true);
     }
     // Session initialization
     if ('' === session_id()) {
         @session_start();
     }
 }