Php 在提交表格之前,我如何保存我的$会话
首先感谢您阅读本文, 我有一个表单,它有3个页面,需要存储第1页和第2页的数据,最后是第3页的数据,然后发送到数据库 我在第2页使用它来存储第1页的信息 (假设在我的表格的第1页上有session_start();) 然后第3页从第2页获取信息,并使用它来保存信息Php 在提交表格之前,我如何保存我的$会话,php,session,Php,Session,首先感谢您阅读本文, 我有一个表单,它有3个页面,需要存储第1页和第2页的数据,最后是第3页的数据,然后发送到数据库 我在第2页使用它来存储第1页的信息 (假设在我的表格的第1页上有session_start();) 然后第3页从第2页获取信息,并使用它来保存信息 $_SESSION['address1']= $_POST['address1']; $_SESSION['address2']= $_POST['address2']; $_SESSION['address3']= $_PO
$_SESSION['address1']= $_POST['address1'];
$_SESSION['address2']= $_POST['address2'];
$_SESSION['address3']= $_POST['address3'];
$_SESSION['email']= $_POST['email'];
$_SESSION['customerType']= $_POST['customerType'];
如果我在第3页回显$u会话['email'],它会显示出来,但如果我在最后一页回显第2页的任何$u会话,它不会显示任何内容
我花了很长时间研究存储会话,但似乎无法解决它
夏季化:-
- 第1页启动会话(session_start()),用户输入姓名、号码、姓氏和手机号码
- 第2页存储用户在第1页输入的信息,用户输入地址、电子邮件并选择会员类型
- 第3页存储用户在第2页上输入的信息,用户选择付款方式(不接受付款,因为我只想知道会员想如何付款,所以选择支票或paypal)
- 第3页还有一条信息没有存储为页面 将所有信息提交到数据库
if ($_REQUEST['p']) { include('includes/'.$_REQUEST['p'].'.php');
所有我的页面将从此页面调用,该页面的格式如下
default.php?p=addmember
default.php?p=addmember-page2
default.php?p=addmember-page3
default.php具有session_start();因此,每个页面都有这个调用。您需要在每个页面中使用
session\u start()
初始化会话。您需要在每个页面中使用session\u start()
初始化会话。是否在每个页面上都调用了session\u start()
session\u start()
创建一个会话或恢复当前会话,因此您需要在每页顶部调用它,而不仅仅是在初始页。您是否在每页都调用了session\u start()
session\u start()
创建一个会话或恢复当前会话,因此您需要在每页的顶部调用它,而不仅仅是在您的初始页。这可能会有所帮助
<?php
session_start();
?>
<?php
#session_destroy();
function form($type)
{
return "<form action=\"\" method=\"POST\" >
<input type=\"text\" name=\"next\" />
<input type=\"submit\" name=\"$type\" />
</form> ";
}
function module()
{
echo form('one');
if (isset($_POST['one'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['title'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
function module2()
{
echo form('two');
if (isset($_POST['two'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['content'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
function module3()
{
echo form('three');
if (isset($_POST['three'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['category'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
if (!isset($_SESSION['title'])) {
echo module();
} else if (isset($_SESSION['title']) && !isset($_SESSION['content'])) {
echo module2();
} else if (isset($_SESSION['content']) && !isset($_SESSION['category'])) {
echo module3();
}
// you can delete, below this line.
echo "<div style=\"width:1000px; align:left; border:1px dashed #darkblue; color: darkblue; font-size:14px; \" />";
function SessionChecker($type)
{
if (isset($_SESSION[$type]) && !empty($_SESSION[$type])) {
echo "Session $type is set as <b>" . $_SESSION[$type] . "</b><br/>";
} else {
echo "Session '$type' is not set <br/>";
}
}
echo SessionChecker('title');
echo SessionChecker('content');
echo SessionChecker('category');
echo "</div>";
也许这会有帮助
<?php
session_start();
?>
<?php
#session_destroy();
function form($type)
{
return "<form action=\"\" method=\"POST\" >
<input type=\"text\" name=\"next\" />
<input type=\"submit\" name=\"$type\" />
</form> ";
}
function module()
{
echo form('one');
if (isset($_POST['one'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['title'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
function module2()
{
echo form('two');
if (isset($_POST['two'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['content'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
function module3()
{
echo form('three');
if (isset($_POST['three'])) {
if (isset($_POST['next']) && !empty($_POST['next'])) {
$_SESSION['category'] = $_POST['next'];
} else {
echo "post is empty";
}
} else {
echo "Please fill the field";
}
}
if (!isset($_SESSION['title'])) {
echo module();
} else if (isset($_SESSION['title']) && !isset($_SESSION['content'])) {
echo module2();
} else if (isset($_SESSION['content']) && !isset($_SESSION['category'])) {
echo module3();
}
// you can delete, below this line.
echo "<div style=\"width:1000px; align:left; border:1px dashed #darkblue; color: darkblue; font-size:14px; \" />";
function SessionChecker($type)
{
if (isset($_SESSION[$type]) && !empty($_SESSION[$type])) {
echo "Session $type is set as <b>" . $_SESSION[$type] . "</b><br/>";
} else {
echo "Session '$type' is not set <br/>";
}
}
echo SessionChecker('title');
echo SessionChecker('content');
echo SessionChecker('category');
echo "</div>";
是,session\u start()
用于启动新会话或恢复已启动的会话。如果我使用session\u start,我会收到以下通知:会话已启动-忽略session\u start()是,session\u start()
用于启动新会话或恢复已启动的会话。如果我使用session_start,我会收到以下通知:一个会话已经启动-忽略session_start(),好的,对不起,我会将此添加到主要问题中。我使用一个名为default.php的页面,然后我使用这个if($\u REQUEST['p']){include($'includes/'.$\u REQUEST['p']..php');所以我使用default.php?p=customeradd,然后它会在每个页面上运行默认值。default.php有会话_start();好的,很抱歉,我会将此添加到主要问题中。我使用一个名为default.php的页面,然后我使用这个if($_-REQUEST['p']){include('includes/'.$_-REQUEST['p']..php');因此我使用default.php?p=customeradd,然后对每个页面运行默认值。default.php具有会话启动();如果我没弄错的话,你想通过存储会话在一页中一页接一页地提交三件事?是吗?是的,我有3页,所有的页面都有用户输入的信息,然后在用户在第3页输入最后一条信息后,所有的页面都必须在第3页提交。给我2分钟,我会编一些东西。哦,天哪真的吗?非常感谢!是的,我需要更多的时间,我只会创建一个脚本,在其中你可以在一个页面中发布所有内容,一个一个使用会话。如果我没有弄错,你想在一个页面中提交三件事,一个接一个,通过存储会话?是吗?是的,我有3个页面,所有页面都有用户输入的信息,并且然后,在用户在第3页输入最后一条信息后,它们都必须在第3页上提交。给我2分钟,我会编一些东西。哦,我的天哪,真的吗?非常感谢!是的,我需要更多的时间,我只会创建一个脚本,在其中你可以在一页中发布所有内容,使用会话逐个发布