title: PHP: Side effects of trimming all values in superglobals ($_GET, $_POST, $_COOKIE, $_REQUEST)
body: <p>I know that many people believe it is wrong to edit Superglobals in PHP. But I found myself to always trim user input in every controller of my webapp. To solve the problem once and for all I now just trim all values of these Superglobals like that:</p>
  
  <pre><code># trim ALL inputs
  foreach ($_REQUEST as $key =&gt; $value) {
      $_REQUEST[$key] = trim($value);
  }
  foreach ($_COOKIE as $key =&gt; $value) {
      $_COOKIE[$key] = trim($value);
  }
  foreach ($_GET as $key =&gt; $value) {
      $_GET[$key] = trim($value);
  }
  foreach ($_POST as $key =&gt; $value) {
      $_POST[$key] = trim($value);
  }
  </code></pre>
  
  <p>Some users might want to define a password that starts or ends with a whitespace. Apart from that I cannot think of any usecase where trimming might do any harm.</p>
  
  <p>Has anybody else tried to trim these Superglobals and ran into strange side effects that I should be aware of?</p>