Data Filtering – A solution?

Standard
This post is over 11 years old and is probably out of date.

Last night in a rather epihanous moment, I had an idea for data filtering.

The idea is simply this, overwrite the GET, POST, REQUEST and COOKIE superglobals with objects.

But, it goes further than this; the major concern most people had with this (as it has been proposed before) is that
older scripts will break, so it is to this that I have come up with a really simple solution.

It works like this:

  1.  
  2.  require_once Crtx/Filter.php;
  3.  Crtx_Filter::Filter();
  4.  
  5.  $_GET[foo] // == original unfiltered data
  6.  $_GET->foo // == filtered data
  7.  ?>

The class is meant to be extended, and the you should add methods named the same
as the expected variables, this will then be passed the variable upon request and the
returned value will be the return value. There is also a __default() method which by default (in Crtx_Filter itself)
simply runs strip_tags() and stripslashes() if magic_quotes_gpc is set to on. You can override this and have your own
default filtering.

Feel free to check out the source, its *really* small: Crtx_Filter Source Code

I really would like comments on this idea…

– Davey