title: PHP - make session expire after X minutes
body: <p>i am using the following technique... </p>
  
  <p>From the <code>login.php</code> the form posts to the page <code>check.php</code> where i do this</p>
  
  <pre><code>&lt;?php    
  $uzer = $_POST['user_name'];
  $pass = $_POST['user_pass'];
  
  require ('DB_connection.php');
  
  $result = mysql_query("SELECT * FROM accounts WHERE user_Name='$uzer' AND user_Pass='$pass'");
  
  if( mysql_num_rows( $result ) &gt; 0)
  {
      $array = mysql_fetch_assoc($result);    
  
      session_start();
      $_SESSION['user_id'] = $uzer;
      header("Location:loggedin.php");            
  }
  else
  {
      header("Location:login.php");
  }
  ?&gt;
  </code></pre>
  
  <p>and on <code>loggedin.php</code> page the first thing i do is</p>
  
  <pre><code>&lt;?php
  session_start();
  if( !isset( $_SESSION['user_id'] ) )
  {
      header("Location:login.php");
  }
  else
  {
      echo ( "this session is ". $_SESSION['user_id'] );
      //show rest of the page and all
  }
  ?&gt;
  </code></pre>
  
  <p>but once logged in when i directly type the url <code>localhost\myProject\loggedin.php</code> it displays the page...which makes perfect sense because the session has started</p>
  
  <p>what i want to implement is</p>
  
  <ul>
  <li>The direct URL \ session  works for 10 minutes after that the session is terminated\expired\timed out and then use must login again and may get the same session id but after 10 minutes use won't be able to browse with the same session</li>
  </ul>
  
  <p><strong>WHAT DO I NEED TO DO OR LEARN</strong></p>