Reputation: 13120
I'm foreach-ing through my POST variables (though I'm using the $_REQUEST)
I want to put all the variables into their own Session variables, but it's simply not working. Does this look incorrect to anyone?
<?php
foreach ($_REQUEST as $posted_name => $posted_value){
$_SESSION[$posted_name].' = '.$posted_value;
}
?>
I am including the session_start() in another part of my script. Above, of course.
Upvotes: 0
Views: 2058
Reputation: 461
You'll need to session_start()
Your final code should look like
<?php
session_start();
foreach ($_POST as $posted_name => $posted_value) {
$_SESSION[$posted_name] = $posted_value;
//You added unnecessary commenting here
}
?>
Upvotes: 0
Reputation: 26167
Are you concatenating a string or are you setting a value?
Try
$_SESSION[$posted_name] = $posted_value;
and what @colighto said.
Upvotes: 0
Reputation: 437336
You intended to write this instead:
$_SESSION[$posted_name] = $posted_value;
Upvotes: 0
Reputation: 77778
There's a big problem with this:
$_SESSION[$posted_name].' = '.$posted_value;
You don't need to use the string concatenation .
to set a session value. This line simple evaluates to a string and doesn't save anything in the $_SESSION
superglobal.
Try this instead
<?php
session_start();
foreach ($_REQUEST as $key => $value){
$_SESSION[$key] = $value;
}
Upvotes: 2