title: PHP redirect link only updates sql database once every minute
body: <p>For tracking the number of clicks (and IP) for a website I created a php script that stores the date and IP info and only once the query was executed successfully it redirects the user to the link. Even though the following script is very minimal, it works.</p>
  <p>However, if I click the link twice within one minute (tested both in Chrome and Edge) it does not save this as a click but it does redirect me to the correct page which I find very odd. I have tried this by clicking multiple times and only the values after +-1 min get stored.</p>
  <p>Opening a new Chrome window does not work. Opening an incognito screen within 1 min does work and this click gets saved.</p>
  <p>Addition info: in the SQL database there is a primary ID column with AUTO_INCREMENT.</p>
  <p><strong>Question</strong>: is there any reason why this happens (perhaps caching?) and would there be any way to prevent this?</p>
  <p>The URL to redirect to link 1 is: <em>thisphpfile.php?link=1</em></p>
  <pre><code>//---------
  // Get info on which link to point to
  $link = $_GET[&quot;link&quot;];
  
  // Check link value to prevent SQL injection
  if($link =='1'){
      $link_sql = &quot;https://www.url1.com&quot;;
  }
  if($link =='2'){
      $link_sql = &quot;https://www.url2.com&quot;;
  }
      
  
  
  // If link was a valid input, continue, else back to homepage
  if($link =='1' || $link == '2'){
  
  
  $date = date(&quot;Y-m-d H:i:s&quot;);
  $ip = $_SERVER['REMOTE_ADDR'];
  
  
  $sql = &quot;INSERT INTO tablename (DATE , IP, LINK) VALUES ('$date', '$ip','$link_sql')&quot;;
  
  //Execute query
  if ($conn-&gt;query($sql) === TRUE) {
  ob_end_flush();
  
  // Redirect link
  header(&quot;Location: &quot; . $link_sql);
  }
  
  }else{
      // Redirect link
      header(&quot;Location: https://www.default.com&quot; );
  }
  </code></pre>