Nathan H
Nathan H

Reputation: 49451

php: Save the entire $_POST variable in the session

Is this valid:

$_SESSION['pictures']['rateAlbum']['_POST'] = $_POST;

I want to save all of the POST data in the session in one shot.

edit: oh and what about the other way around:

$_POST = $_SESSION['pictures']['rateAlbum']['_POST'];

Upvotes: 2

Views: 10569

Answers (2)

xkeshav
xkeshav

Reputation: 54084

you can use directly write below

$_SESSION['input_array']=$_POST[];

and if your $_POST['username']='Hello'; then $_SESSION['input_array']['username'] would display 'hello' and if $_POST['birthday']['year']='2002' then $_SESSION['input_array']['birthday']['year'] would display 2002

Upvotes: 1

Marcx
Marcx

Reputation: 6836

yes you can... if you save $_POST in $_SESSION in session you'll have the same array as post...

You can also do the other way and save something to $_POST..

you can also do that (or, using $_SESSION):

   $_POST = array('field1' => 'val1',
       'field1' => 'val1',
       'field1' => 'val1',
       'fieldn' => 'valn');        
   $_SESSION=$_POST;

or

   $test="hi";
   $_SESSION['field1']="test";
   echo $$_SESSION['field1']; //this print hi       

PHP is really flexible and let you do almost everthing, obviously pay attention on security problem...

Upvotes: 5

Related Questions