Hi everyone!
I'm dealing with an online test that has 100+ questions and I would like a way to:
a) turn all $_POST into $_SESSION automatically
b) clean the data
c) encode it
a) I found this but it makes the form fail
if(isset($_POST) {
foreach ($_POST as $key => $val) {
if($val != "Submit")
$_SESSION["$key"] = $val;
}
}
I have also read that doing this might be a security problem but having to deal with 100+ questions and turn them from POST to SESSION leaves lots of work (and room for error).
b) I found this
function clean($value)
{
if (get_magic_quotes_gpc()) $value = stripslashes($value);
if (!is_numeric($value)) $value = mysql_real_escape_string($value);
return $value;
}
array_walk($_GET,'clean');
array_walk($_POST,'clean');
array_walk($_COOKIE,'clean');
extract($_GET,EXTR_PREFIX_ALL,'get');
extract($_POST,EXTR_PREFIX_ALL,'post');
extract($_COOKIE,EXTR_PREFIX_ALL,'cookie');
I'm not really sure if this works. Is there any to check if the data is 'clean'?.
c) I made this (looking at the code from (b)
function encode($postedvariable)
{
if (get_magic_quotes_gpc()) $value = utf8_encode($postedvariable);
if (!is_numeric($postedvariable)) $value = utf8_encode($postedvariable);
return $value;
}
array_walk($_GET,'encode');
array_walk($_POST,'encode');
array_walk($_COOKIE,'encode');
extract($_GET,EXTR_PREFIX_ALL,'get');
extract($_POST,EXTR_PREFIX_ALL,'post');
extract($_COOKIE,EXTR_PREFIX_ALL,'cookie');
Can any one help me?