title: Prevent URL Injections
body: <p>My website was recently got <strong>Hacked/Compromised</strong>. Via google I have learnt it is a victim of site injections. I believe I have cleaned and hopefully secured my website but I'm looking for ways to prevent it from ever happening again. I came across a code (see below) and wanted to know whether it will </p>
  
  <p>1) work to prevent such attacks in the future? and</p>
  
  <p>2) where should I add this code as my website is built in WordPress.</p>
  
  <p>Any help or even better codes anyone can provide will be greatly appreciated, I'm new to programming. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>&lt;?php
  if(isset($_REQUEST["id"])){
  
  if(!is_int($_REQUEST["id"])){
  
  //redirect this person back to homepage
  
  } else {
  
  $id_raw = trim(htmlentities($_REQUEST["id"]));
  $id_secure = mysql_real_escape_string($id_raw);
  $sql = "SELECT * FROM databasetable WHERE id='".$id_secure."'";
  
  }
  }
  ?&gt;
  </code></pre>