Loop through $_SESSION and assisn to non-session variables

I’m trying to find a way to loop through a session where I may not know all the key names and assign the values to normal variables with the same names. I’ve tried a few things without success. Anybody know how to do this?

(I realize this has security implications, so I’m validating the data very thoroughly.)

How can you validate each field thoroughly when you don’t even know their names. To validate thoroughly you need to know what each field is supposed to contain and so you should reasonably expect to know a fields name if you know what its expected content is.

The code to copy all the session variables without validating them would be:

while (list ($key, $val) = each ($_SESSION)) {
    $$key = $val;
}

that of course does not allow for each to be validated thoroughly with its ownfield specific validation as you move it. You’d need to code each field separately to do that.

Thanks, I’ll give that a try.

The validation is clumsy, perhaps, but effective. Basically, I don’t know the field names but I do know that each of them should contain only letters or numbers. So I’m first looping through the $_SESSION array and running each value through a preg_replace that strips out everything except letters and numbers and reassigns the new values.