php - PHP头位置变量重定向和主页输出
问题描述
我有一个页面,form
它发出一个 POST 请求,并且在我输入姓氏的地方有一个输入。
提交表单后,我想从SESSION['surname']
提交的变量中获取,然后通过header("Location...")
.
我希望最后一个变量名称出现在表单下的主页上。怎么做?
有人可以指导吗?
解决方案
类似的东西;带有表格的主页:
<form action="src/session.php" method="POST">
<div>SESSION</div>
<div>
<label for="surname">Surname</label>
<input name="surname">
</div>
<button type="submit" name="approve" value="approval">Send</button>
</form>
在 src/session.php 中:
<?php
if($_POST['approve']) {
$_SESSION['surname'] = urlencode($_REQUEST['surname']);
$var = $_SESSION['surname'];
}
header("Location: https://...."); #here should be the home page with the form and after redirect i want to see exactly same form but with $var underneath it
?>
推荐阅读
- java - 如何在 Appium 中列出列表中的所有元素
- python - 将文本从一个单元格复制到另一个单元格而不删除原始内容python
- git - 无法 ping github,但可以在我的工作场所通过浏览器访问 github。我运气不好?
- flutter - Flutter 错误原因:SocketException: Failed to create server socket (OS Error: Failed to start accept), address = localhost, port = xxxx
- python - Altair 生成带有水平连接表的水平条形图
- ios - 尝试制作 UIAlertController,似乎无法初始化
- xamarin - 设置 BindingContext 后调用 Xamarin 表单的 Prism Initialize
- automation - 通过自动完成相同的工作
- python - 需要两个参数或都不使用 argparse
- php - 使用 uasort() php 按多个条件排序