RE: An easier way? $_POST[] => $_SESSION[]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Erich Kolb wrote:
> Is there an easier way to assign all post data from a form to session
> data?
>
> Eg.,
>
> $_SESSION['first_name'] = $_POST['first_name'];
> $_SESSION['last_name'] = $_POST['last_name'];
>
> $_SESSION['email'] = $_POST['email'];

You could do this:

$_SESSION = array_merge($_SESSION, $_POST);

Although it might be better to ensure that only known valid keys from $_POST are
making their way into $_SESSION, doing something like this:

$keys = array('first_name', 'last_name', 'email');
foreach ($keys as $key) {
  if (isset($_POST[$key])) { $_SESSION[$key] = $_POST[$key]; }
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux