title: If statement, sessions variables
body: <p>The following code is within an ajax call. I'm trying to make sure people don't vote on questions with a certain id too often using sessions.</p>
  
  <p>So they click a button, which executes the following php code:</p>
  
  <pre><code>  $id=$_GET["id"];
  
  
  if ((isset($_SESSION["$id"]) &amp;&amp; ((time() - $_SESSION["$id"]) &gt; 180)) || (!isset($_SESSION["$id"]))) {
      // last vote was more than 3 minutes ago
      $_SESSION["$id"] = time(); // update/create vote time stamp
  
  
      //there is code here to add the vote to the database
  }
  else{
  echo "sorry, you've already voted recently";
  }
  </code></pre>
  
  <p>So I'm creating a session variable for each question id which holds the <code>time()</code> of their last vote. I would do this with cookies, but they can be disabled.</p>
  
  <p>Currently, there is a bug somewhere with my logic, because it allows the user to keep clicking the button and adding as many votes as they want.</p>
  
  <p>Can anyone see an error that I have made?</p>