会话php语句
我如何将其命令放入一个语句中,该语句将所有 $_POST[] 放入会话中,而不必写出每一行。
<?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'];
?>
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'];
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你不喜欢Marc B的嵌套,
If you don't like the nesting of Marc B,
如果您有理由选择哪些
$_POST
值进入会话存储,哪些不进入会话存储(例如,如果您有每次都必须重新输入的验证码,或者信用卡号或敏感信息),创建一个$_POST
键数组来存储和迭代它:If you have a reason to be selective about which
$_POST
values go to session storage and which don't (for example, if you had a CAPTCHA that had to be re-entered each time, or a credit card number or something sensitive), make an array of the$_POST
keys to store and iterate over it:将创建 $_POST 数组的副本并将其分配给 $_SESSION,这将完成您所要求的任务。但这也会清除 $_SESSION 数组中的所有数组成员。所以我推荐一个循环,它将维护 $_SESSION 中已有的数组成员。
Would create a copy of the $_POST array and assign it to $_SESSION, which accomplishes what you are asking. But this will also wipe out any array members in the $_SESSION array. So I recommend a loop, which will maintain the array members already in $_SESSION.
试试这个;)
不要直接将
$_POST
分配给$_SESSION
,而是创建一个像这样的嵌套分数:在这种情况下,您的
session
数据也是post
数据分配后即可使用。Try this ;)
Instead of direct assigning
$_POST
into$_SESSION
create a nested score like this:In this case, your
session
data is also available for you afterpost
data assignment.