I have a form that uses session variables. If the user makes an error filling out the form, the form will be displayed again with an error message, and the php script repopulates all the fields that a user has entered so they don't need to be entered again.
But i think session variables can't be overwritten by $_POST , right? So I need to unset all the session variables after the form is repopulated, so if the user changes something the new values will be saved.
If i use this, it works correctly:
session_unregister("var1");
session_unregister("var2");
But I want to loop through the whole set of variables. So I make an array of all the variables in the form, store it in $formVars and try to unregister them. This doesn't work, the variables don't get unset:
for ( $i = 0; $i < count($formVars); $i++ )
{
session_unregister($formVars[$i]);
}
What is the correct way to do this, or a better way?