如何跨多个页面传递多个变量? [英] How to pass multiple variables across multiple pages?

查看:123
本文介绍了如何跨多个页面传递多个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站涉及一个用户通过几页表单提交数据.我可以将在一页上提交的数据直接传递到下一页,但是之后如何将其发送到页面呢?这是我正在做的非常简化的版本.

My website involves a user submitting data over several pages of forms. I can pass data submitted on one page straight to the next page, but how do I go about sending it to pages after that? Here's a very simplified version of what I'm doing.

第1页:

<?php
echo "<form action='page2.php' method='post'>
Please enter your name: <input type='text' name='Name'/>
<input type='submit' value='Submit'/></form>";
?>

第2页:

<?php
$name=$_POST["Name"];
echo "Hello $name!<br/>
<form action='page3.php' method='post'>
Please enter your request: <input type='text' name='Req'/>
<input type='submit' value='Submit'/></form>";
?>

第3页:

<?php
echo "Thank you for your request, $name!";
?>

最后一个页面应该显示用户名,但是很显然它不起作用,因为我没有将该变量传递给页面.由于复杂的原因,我无法在同一页面上提交所有数据,因此我需要将所有内容拆分.那么我怎样才能得到这个变量和其他变量呢?

The final page is supposed to display the user's name, but obviously it won't work because I haven't passed that variable to the page. I can't have all data submitted on the same page for complicated reasons so I need to have everything split up. So how can I get this variable and others to carry over?

推荐答案

使用会话:

session_start();

$_SESSION['name'] = $_POST['name'];

然后在第3页上,您可以回显$_SESSION['name']

then on page3 you can echo $_SESSION['name']

这篇关于如何跨多个页面传递多个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆