title: PHP Security - (int) vs FILTER_VALIDATE_INT
body: <p>I recently was told there is FILTER_VALIDATE_INT which is great by the way. </p>
  
  <p>My question is in terms of taking an integer value from the website whether it maybe from user or generated from the web application, and passed via query string. </p>
  
  <p>The value (integer) may be displayed or used in mysql query.</p>
  
  <p>I am trying to structure the best possible security method for this. </p>
  
  <p>With that in mind, is it safe to simply use </p>
  
  <pre><code>$myNum = (int)$_GET['num'];
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>if (filter_var($_GET['num'], FILTER_VALIDATE_INT)) $myNum = $_GET['num'];
  </code></pre>
  
  <p>Also, please explain what is the difference between using <code>(int)</code> and <code>FILTER_VALIDATE_INT</code></p>