Reputation: 3701
I'm creating a multi-step survey and want to store the data in $_SESSION
before writing everything to a database. Is there anything I should be doing to the data before storing it there from a security perspective?
Upvotes: 0
Views: 4103
Reputation: 2113
well, to avoid problems recovering the data, i suggest you to use a name for the session and use an array exclusively for the post data, kinda:
$_SESSION['postData'] = $_POST;
Upvotes: 3
Reputation: 360912
Assuming you're on the regular file-based sessions, then you don't have much to worry about from an injection vulnerability view. PHP will take care of the mechanics of read/writing the session file, using serialize()
and the like. Stuff whatever you want into $_SESSION and it'll magically be there on the next page invocation.
However, from the broader security perspective, anything that goes into the session file IS readable by anything else running under the same web server instance (e.g. the apache user ID). So it's not somewhere you could store sensitive data, let along things like credit cart/cvv numbers.
Upvotes: 4
Reputation: 8354
Its fairly safe to throw whatever you want in the session without sanitizing it. You could though, since you're going to anyways, sanitize it before putting it in the session so its ready to go into the database, then you can sleep more soundly.
Upvotes: 1