Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing all POST data in SESSION

Tags:

php

session

I have more values (over 20) from $_POST like this...

$name = $_POST['name'];
$username = $_POST['username'];
$city = $_POST['city'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];

NOTE : I have prevented there values from SQL injection.

My question is can I know is there a way to store all these POST values in SESSION at once? Instead of this method..

$_SESSION['name'] = $name; etc

any answers will be highly appreciated. Thank you.

like image 552
TNK Avatar asked Jan 22 '13 18:01

TNK


People also ask

How much data can be stored in a session?

Session storage can also accommodate a huge amount of data. Most browsers, including Chrome and Firefox, can store about 10 MBs of data in session storage.

What kind of data is stored in session?

A session is a global variable stored on the server. Each session is assigned a unique id which is used to retrieve stored values. Whenever a session is created, a cookie containing the unique session id is stored on the user's computer and returned with every request to the server.

Can I store object in session?

Yes, You can save the class objects/instance in session and access at other pages.


1 Answers

You can add one array to another.
$_POST and $_SESSION are just arrays.
Note that the keys in the second array take priority in case of duplicates.

$_SESSION += $_POST;

However, I don't see this ending well, since the client side can inject anything he wants to the session, E.G. hijacking your users session id.

like image 137
Mirko Adari Avatar answered Oct 04 '22 17:10

Mirko Adari