again with another problem.
public function __construct() {
$_GET = $this->clean($_GET);
$_POST = $this->clean($_POST);
...
}
public function clean($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$this->clean($key)] = $this->clean($value);
}
} else {
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
}
return $data;
}
i dont understand why $data[$this->clean($key)] = $this->clean($value); is calling its own function. what is the point of doing this? the advantages
thanks,
daniel
It’s a technique called recursion. This particular function descends into the structure until it is dealing with very simple data and sanitizes it all.
Given this:
It would start:
<fooan array? (no)<foobecomes<foo<fooused as a key<fooan array? (yes)batremains as is (still has htmlspecialchars called, but it does not change anything))'OMGWTFBBQ!!><!?!'an array (no)?'OMGWTFBBQ!!><!?!'is converted to'OMGWTFBBQ!!><!?!''OMGWTFBBQ!!><!?!'is used for the value for bat.barreturned as is (like bat above)bazreturned as is.You can think of it this way