title: session that works for 24/7 like facebook
body: <p>I have been working on sessions that has to work for 24/7 that don't get logout until user logged out exactly like 'facebook'. I have tried to write code and it didn't work so I googled for it and unfortunately din't find any working solution So here I came. I tried only sessions first but din't work so I was using sessions with cookies with cookie expiry time of after 10 years but still it din't work. My code is</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>include_once('includes/open-pdo.php');
  include_once 'model.php';
  if(!empty($_SESSION["is_logged_in"])) {
   header('Location: dashboard.php');exit;
  }
  if(!empty($_COOKIE["member_login"])) {
    $username = trim($_COOKIE["member_login"]);
    $password = trim($_COOKIE["member_password"]);
    $valid_user_details = check_user_login($username, $password);
    if(count($valid_user_details)&gt;0 &amp;&amp; $valid_user_details['user_id'] &gt; 0){
      $_SESSION['ses_user_id'] = $valid_user_details['user_id'];
      $_SESSION['ses_username'] = $valid_user_details['user_name'];
      $_SESSION['ses_user_email'] = $valid_user_details['user_email'];
      header('Location: dashboard.php');exit;
    }else{
      header('location: index.php?action=logout');exit;
    }
  }
  if(!empty($_POST['submit'])){
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $valid_user_details = check_user_login($username, $password);
    if(count($valid_user_details)&gt;0 &amp;&amp; $valid_user_details['user_id'] &gt; 0)
    {
     $_SESSION['ses_user_id'] = $valid_user_details['user_id'];
     $_SESSION['ses_username'] = $valid_user_details['user_name'];
     $_SESSION['ses_user_email'] = $valid_user_details['user_email'];
     $_SESSION['is_logged_in'] = true;
     /* Store COOKIES of duration for 10 years expiry */
     setcookie ("member_login",$_POST["username"],time()+ (10 * 365 * 24 * 60 * 60));
     setcookie ("member_password",$_POST["password"],time()+ (10 * 365 * 24 * 60 * 60));
     header('Location: dashboard.php');exit;
    }else{
     header('location: index.php?action=logout');exit;
    }
  }
  &lt;body&gt;
   &lt;form class="form-signin" action="" method="post"&gt; 
    &lt;input type="text" class="form-control" name="username" placeholder="Email Address" required="" autofocus="" /&gt;
    &lt;input type="password" class="form-control" name="password" placeholder="Password" required=""/&gt;
    &lt;button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="submit"&gt;Login&lt;/button&gt;   
   &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>dashboard.php</strong></p>
  
  <pre><code>if(empty($_COOKIE["member_login"]) || empty($_SESSION["is_logged_in"])) {
   header('location: index.php?action=logout');exit;
  }
  echo '&lt;div style="text-align:center;"&gt;&lt;h3&gt;Welcome to Dashboard - &lt;b&gt;'.$_SESSION['ses_username'].'&lt;/b&gt;&lt;/h3&gt;';
  echo '&lt;span style="font-size:20px;"&gt;&lt;a href="logout.php"&gt;logout&lt;/a&gt;&lt;/span&gt; &lt;/div&gt;';
  </code></pre>
  
  <p>Anyone out there please help me out in this. Thanks.</p>