3

Tengo este código para validar seguridad:

$tipos = array('$_POST','$_GET','$_COOKIE','$_SESSION','$_FILES');
foreach($tipos as $tipo){
    if ( isset($$tipo) && !empty($$tipo) ) {
        foreach ($$tipo as $key => $item) {
            $tipo[$key] = $this->security->xss_clean($item);
        }
    }
}

Me da error de undefined variable, se que podria validarlo uno por uno, pero hay solución de esta forma?

1 respuesta 1

2

En el segundo foreach debes usar $$tipo[$key] en vez de $tipo[$key] y tu array tipos no deben tener el $. Debería quedar así:

$tipos = array('_POST','_GET','_COOKIE','_SESSION','_FILES');
foreach($tipos as $tipo){
    if ( isset($$tipo) && !empty($$tipo) ) {
        foreach ($$tipo as $key => $item) {
            $$tipo[$key] = $this->security->xss_clean($item);
        }
    }
}
1
  • Me sale: <p>Message: Undefined variable: _POST</p>
    – Exale
    el 1 oct. 2018 a las 14:02

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.