Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session php statement

Tags:

php

session

how can i command this into a statement that will just put all the $_POST[] into a session without have to write each line out.

<?php session_start(); 
$_SESSION['s_type'] = $_POST['s_type'];
$_SESSION['s_uname'] = $_POST['s_uname'];
$_SESSION['s_email'] = $_POST['s_email'];
$_SESSION['s_promo'] = $_POST['s_promo'];
$_SESSION['s_ctry'] = $_POST['s_ctry'];
?> 
like image 522
acctman Avatar asked Mar 03 '26 10:03

acctman


2 Answers

$_SESSION['POST'] = $_POST;
echo $_SESSION['POST']['s_type'];
like image 64
Marc B Avatar answered Mar 04 '26 23:03

Marc B


If you don't like the nesting of Marc B,

foreach ($_POST as $k => $v){
    $_SESSION[$k] = $v;
}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!