有两种方法可以做到这一点
要将数据从一个页面传递到另一个页面,首先需要调用session_start()将要使用$_SESSION超全局变量的所有页面.然后,您可以使用在会话中存储您的值
$_SESSION['name'] = $_POST['name'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['pin'] = $_POST['pin'];
Run Code Online (Sandbox Code Playgroud)
要在第二页中使用这些值,只需按名称调用它们即可.例如:
$name = $_SESSION['name']; // will contain the value entered in first page
Run Code Online (Sandbox Code Playgroud)
================================================== ================================
这更像是一种乏味的方法,但它完成了这项工作.该过程涉及将需要传递的数据存储到隐藏字段中的不同页面,然后通过$_POST或$_GET超全局访问它们.
page1.php(发布到page2.php)
<input type="text" value="Page 1 content" name="content" />
<input type="text" value="Page 1 body" name="body" />
Run Code Online (Sandbox Code Playgroud)
page2.php(发布到page3.php)
<input type="hidden" value="<?php echo $_POST['content']; ?>" name="content" />
<input type="hidden" value="<?php echo $_POST['body']; ?>" name="body" />
<input type="text" value="Page 2 content" name="content2" />
<input type="text" value="Page 2 body" name="body2" />
Run Code Online (Sandbox Code Playgroud)
page3.php
echo $_POST['content']; // prints "Page 1 content"
echo $_POST['body']; // prints "Page 1 body"
echo $_POST['content2']; // prints "Page 2 content"
echo $_POST['body2']; // prints "Page 2 body"
Run Code Online (Sandbox Code Playgroud)