By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

About copying $_POST variables to $_SESSION-simple clarification needed

P: 58
I was reading one of the past thread supported by Pbmods.And as always contributing with excellence,he recommended this code for session management

foreach($_POST as $key => $val)
$_SESSION[$key] = $val;


This translates all POST variables into the Session one.

Am just wondering if i put that declaration on top of a script do I really need to declare them individually like :

$_SESSION['First_Name'] = $_POST['First_Name'];
$_SESSION['Last_Name'] = $_POST['Last_Name'];


or just leave them as below and the above code will take care of copying it.

$First_Name = $_POST['First_Name'];
$Last_Name = $_POST['Last_Name'];

$sql="INSERT INTO userinfo (First_Name, Last_Name, Email)


Currently I just leave them as POST and only echo the session in input fields like:
<?php echo $_SESSION['First_Name']?>

Thank you in advance for any clarifications !
Aug 4 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 5,821
Heya, Jankie.

The statement:
Expand|Select|Wrap|Line Numbers
  1. foreach($_POST as $key => $val)
  2.     $_SESSION[$key] = $val;
copies ALL post variables to the session. Therefore, when you execute this code, there is no need to individually copy any variables.
Aug 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.