title: cleaning $_POST variables
body: <p>I'm trying to come up with a way to effectively easily clean all POST and GET variables with a single function. Here's the function itself:</p>
  
  <pre><code>//clean the user's input
  function cleanInput($value, $link = '')
  {
      //if the variable is an array, recurse into it
      if(is_array($value))
      {
          //for each element in the array...
          foreach($value as $key =&gt; $val)
          {
              //...clean the content of each variable in the array
              $value[$key] = cleanInput($val);
          }
  
          //return clean array
          return $value;
      }
      else
      {
          return mysql_real_escape_string(strip_tags(trim($value)), $link);
      }
  }
  </code></pre>
  
  <p>And here's the code that would call it:</p>
  
  <pre><code>//This stops SQL Injection in POST vars
  foreach ($_POST as $key =&gt; $value)
  {
      $_POST[$key] = cleanInput($value, $link);
  }
  
  //This stops SQL Injection in GET vars
  foreach ($_GET as $key =&gt; $value)
  {
      $_GET[$key] = cleanInput($value, $link);
  }
  </code></pre>
  
  <p>To me this seems like it should work. But for some reason it won't return arrays from some checkboxes I have in a form. They keep coming out blank.</p>
  
  <p>I've tested my code without the above function and it works fine, I just want that added bit of security in there.</p>
  
  <p>Thanks!</p>