]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
fix of #115 - stay connected and session livetime 567/head
authorMaryana Rozhankivska <mariroz@mr.lviv.ua>
Mon, 17 Mar 2014 20:22:05 +0000 (22:22 +0200)
committerMaryana Rozhankivska <mariroz@mr.lviv.ua>
Mon, 17 Mar 2014 20:22:05 +0000 (22:22 +0200)
inc/3rdparty/Session.class.php
inc/poche/Poche.class.php
index.php

index 599b68cdb0e173b63d36759bba470e5a00516d72..4ee5d1da80759fbbe62664e06e83d5731e2c7f77 100644 (file)
@@ -31,9 +31,9 @@ class Session
     public static $sessionName = '';
     // If the user does not access any page within this time,
     // his/her session is considered expired (3600 sec. = 1 hour)
-    public static $inactivityTimeout = 86400;
+    public static $inactivityTimeout = 3600;
     // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours)
-    public static $longSessionTimeout = 604800; // 604800 = a week
+    public static $longSessionTimeout = 7776000; // 7776000 = 90 days
     // If you get disconnected often or if your IP address changes often.
     // Let you disable session cookie hijacking protection
     public static $disableSessionProtection = false;
@@ -48,8 +48,13 @@ class Session
     /**
      * Initialize session
      */
-    public static function init()
+    public static function init($longlastingsession = false)
     {
+        //check if session name is correct
+        if ( session_id() && session_id()!=self::$sessionName ) {
+            session_destroy();
+        }
+
         // Force cookie path (but do not change lifetime)
         $cookie = session_get_cookie_params();
         // Default cookie expiration and path.
@@ -61,12 +66,19 @@ class Session
         if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
             $ssl = true;
         }
-        session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl);
+
+        if ( $longlastingsession ) {
+            session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true);
+        }
+        else {
+            session_set_cookie_params('', $cookiedir, $_SERVER['HTTP_HOST'], $ssl, true);
+        }
+
         // Use cookies to store session.
         ini_set('session.use_cookies', 1);
         // Force cookies for session  (phpsessionID forbidden in URL)
         ini_set('session.use_only_cookies', 1);
-        if (!session_id()) {
+        if ( !session_id() ) {
             // Prevent php to use sessionID in URL if cookies are disabled.
             ini_set('session.use_trans_sid', false);
             if (!empty(self::$sessionName)) {
@@ -115,6 +127,9 @@ class Session
         if (self::banCanLogin()) {
             if ($login === $loginTest && $password === $passwordTest) {
                 self::banLoginOk();
+
+                self::init($longlastingsession);
+
                 // Generate unique random number to sign forms (HMAC)
                 $_SESSION['uid'] = sha1(uniqid('', true).'_'.mt_rand());
                 $_SESSION['ip'] = self::_allIPs();
@@ -135,6 +150,7 @@ class Session
             self::banLoginFailed();
         }
 
+        self::init();
         return false;
     }
 
index f85bb86cea08bf6c4de246f8cb0b0ac864f5b2b2..b1143d0b584a4c1a968fd0352676dafa877e42ca 100755 (executable)
@@ -61,8 +61,6 @@ class Poche
     private function init() 
     {
         Tools::initPhp();
-        Session::$sessionName = 'poche'; 
-        Session::init();
 
         if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
             $this->user = $_SESSION['poche_user'];
index 5ca8bef5b3de0af9c49a2737cd8859efd034c5c2..bc28a19d59299be677a6f547d59b21a0f25d2997 100644 (file)
--- a/index.php
+++ b/index.php
@@ -12,6 +12,12 @@ define ('POCHE', '1.5.3');
 require 'check_setup.php';
 require_once 'inc/poche/global.inc.php';
 
+# Start session
+Session::$sessionName = 'poche';
+if ( !isset($_GET['login']) ) {
+    Session::init();
+}
+
 # Start Poche
 $poche = new Poche();
 $notInstalledMessage = $poche -> getNotInstalledMessage();