title: What is the best way to make "remember me" under php when using native sessions?
body: <p>Previously i was creating additional cookie "rememberme" with unique hash, that was stored in the database, mapped to the user id.</p>
  
  <p>If user had such cookie - website tried to find it's value in database, and if it was found session was setting up.</p>
  
  <p>Later, developing new project i thought that it is maybe not very secure to generate this unique hash by myself, and keeping two cookies (native "PHPSESSID" + my "rememberme") for one operation (user identification) is overkill.</p>
  
  <p>Maybe there is a way to setup not global session lifetime, but to setup it individually for different user sessions... or maybe it is better to keep user sessions in the database, mapped to the userid?</p>
  
  <p><strong>UPDATE 1</strong>
  I thought if it is so hard to make "remember me" button, we can go another way - to make "Not my computer button". Idea is to set default cookie_lifetime for a week in php.ini (for example), and if user checkes this checkbox - we will set cookie_lifetime into zero using session_set_cookie_params  function.</p>
  
  <p>So, 1st question is - will session_set_cookie_params affect other users cookies (in documentation it is said, that session_set_cookie_params options will have effect until php process will be executing)</p>
  
  <p>2d question is that if session_set_cookie_params is not affecting global settings, will session regeneration affect users, that don't want to keep a long-life cookie?</p>
  
  <p><strong>UPDATE 2: [Question 1 answer]</strong> </p>
  
  <p>Just tested session_set_cookie_params function.
  I wrote a script, that sets session cookie lifetime into zero using session_set_cookie_params and then executing for 30 seconds:</p>
  
  <pre><code>if ($_GET['test']) {
    session_set_cookie_params (0);
    while (true) {
      sleep(1);
    }
  }
  session_start();
  </code></pre>
  
  <p>So, in first browser i just started this script with ?test=1 parameter, just after that (while this script was executing) i started this script without parameters in the second browser. The answer is no - second browser's cookie was not affected. It had lifetime, that was specified in php.ini</p>
  
  <p><strong>UPDATE 3: [Question 2 answer]</strong>
  Then, i've tried to check if regeneration affects session cookie lifetime, that was set by session_set_cookie_params.</p>
  
  <p>Yes, it affects. If i set session cookie with customized lifetime, that was set by session_set_cookie_params, and then call session_regenerate_id(), cookie will have lifetime, set in php.ini</p>
  
  <p>But, if we set session_set_cookie_params (0) before calling session_regenerate_id(), our cookie will have correct lifetime.</p>
  
  <p>So, that's it! That was easy! 8)</p>
  
  <p>Thank you, ladies and gentlemen!</p>