title: How to increment a session value in php
body: <p>I'm working on a login system. I have my login form which posts to check.php.</p>
  
  <p>I'm trying to write a function to test the number of failed login attempts if the user details are incorrect.</p>
  
  <pre><code>&lt;?php
  //from check.php
  if (blah)
  {
      $_SESSION['error'] = "&lt;strong&gt;Details not correct.&lt;/strong&gt; Please try again.";     
      //$_SESSION['email'] = $email;
      $_SESSION['attempts'] = 1; //first attempt
      if(isset($_SESSION['attempts']))
      {
          $_SESSION['fail'] = $_SESSION['attempts']++; //increment
      }
      //$_SESSION['fail'] is echo'd on my login form 
  }
  </code></pre>