-1

I'm trying to automatically sanitize input on an array of global variables like so:

$sanitize = array('_POST', '_GET', '_REQUEST', '_COOKIE', '_SESSION');
foreach($sanitize as $type){
    $property = trim(strtolower($type), '_');
    $this->$property = $this->cleanse($$type);
}

But I get: Notice: Undefined variable: _REQUEST (and so on for all of the global variables I'm trying)

Is doing what I'm trying to accomplish actually possible?

Thanks.

wyqydsyq
  • 1,992
  • 1
  • 20
  • 28
  • 1
    Works on php 5.3 here. Not that it should. variable variables are inherently evil. – Marc B Feb 23 '12 at 05:39
  • 1
    okay, here is an explanation you asked for. [What's the best method for sanitizing user input with PHP?](http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php) – Your Common Sense Feb 23 '12 at 05:50

1 Answers1

2

Doing this on a global scale is typically frowned upon.

I'd recommend using some of PHP's built in Filters to achieve what you want at a local level. That is just filter what you need as you need it.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174