title: how to use time() to count how many seconds you logged in
body: <p>I'm creating a script and let's say I have a user/pass to enter and once it's entered another page will be redirected and in that page will show a line sayingi you have been staying here for xxx seconds.</p>
  
  <p>I'm using $_SESSION at the moment but I'm not sure how to set up so time() will start counting after logged in.</p>
  
  <p>this is my index.php script</p>
  
  <pre><code>if((isset($_GET["user"])) || (isset($_GET["pass"])))
  {
      if(($_GET["user"] == "a") &amp;&amp; ($_GET["pass"] == "a"))
      {
          session_start();
      $_SESSION["auth"] = 1;
      $_SESSION["username"] = $_GET["user"];
      $_SESSION["loginTime"] = time();
      $_SESSION["timeLogged"] = time() - $_SESSION["loginTime"];
  
  
      header("Location: 1.php");
  }
  else
  {
      echo "Incorrect login data";
  }
  }
  </code></pre>
  
  <p>this is my 1.php script</p>
  
  <pre><code>session_start();
  if(!(isset($_SESSION["username"])))
  {
      header("location: index.php");
  }
  else
  {
      echo "Welcome " . $_SESSION["username"] . "&lt;br/&gt;";
      echo "You have been logged in for " . $_SESSION["timeLogged"] . " seconds.";
  }
  </code></pre>