我在Session中维护变量时遇到问题。我已经确认通过页面导航保持相同的会话ID,并且我还使用Print_r($_SESSION)
来监视变量。
我正在使用四页。
在第一页上,我使用表单将数据发送到下一页。
<form name="prescreen" action="custinfo.php" method="post">
<label>From DIA</label>
<input name="startlocation" id="fromdia" type="radio" value="From DIA">
<label>To DIA</label>
<input name="startlocation" id="todia" type="radio" value="To DIA">
<label>Choose Location:</label>
City:<input name="city" id="city" type="text" />
<span>or</span><br />
Zipcode:<input name="zipcode" id="zipcode" type="text" />
<h3>When do you need picked up?</h3>
<label>Choose Date:</label>
<input name="date" id="date" type="datetime-local" />
<label>Choose Time:</label>
<input name="time" id="time" type="time" />
<input type="submit" value="Get a Ride Now!" class="textbtn"></input>
</form>
在custinfo.php上,我然后在文档的头部使用它:
<?php
session_start();
$_SESSION['testvar'] = 'THIS IS A TEST';
$startlocation = $_POST["startlocation"];
$city = $_POST["city"];
$zipcode = $_POST["zipcode"];
$date = $_POST["date"];
$time = $_POST["time"];
//Assign variables to the Session
$_SESSION['startlocation'] = $startlocation;
$_SESSION['city'] = $city;
$_SESSION['zipcode'] = $zipcode;
$_SESSION['date'] = $date;
$_SESSION['time'] = $time;
?>
正确读入变量并将其存储在数组中。然后我在custinfo.php页面中使用这个表单:
<form name="customerinfo" action="custbilling.php" method="post">
<label>Contact Name</label>
<input name="contactname" id="contactname" type="text">
<label>Contact Email</label>
<input name="contactemail" id="contactemail" type="text">
<label>Contact Phone</label>
<input name="contactphone" id="contactphone" type="text" />
<?php
if($_SESSION['startlocation'] == "From DIA")
{
echo '<hr />';
echo '<label><b>To Location:</b></label>';
echo 'Address1:<input name="toaddress1" id="toaddress1" type="text" />';
echo 'Address2:<input name="toaddress2" id="toaddress2" type="text" />';
echo 'City:<input name="tocity" id="tocity" type="text" />';
echo 'Zip:<input name="tozip" id="tozip" type="text" />';
echo '<hr />';
}
else
{
echo '<hr />';
echo '<label><b>From Location</b></label>';
echo 'Address1:<input name="fromaddress1" id="fromaddress1" type="text" />';
echo 'Address2:<input name="fromaddress2" id="fromaddress2" type="text" />';
echo 'City:<input name="fromcity" id="fromcity" type="text" />';
echo 'Zip:<input name="fromzip" id="fromzip" type="text" />';
echo '<hr />';
}
?>
<input type="submit" value="Book Your Ride!" class="textbtn"></input>
</form>
在custbilling.php页面的头部,我把所有内容都拉进去了:
<?php
session_start();
/*Vars from Customer Info */
$contactname = $_POST['contactname'];
$contactemail = $_POST['contactemail'];
$contactphone = $_POST['contactphone'];
if($_SESSION['startlocation'] == "To DIA")
{
$address1 = $_POST['fromaddress1'];
$address2 = $_POST['fromaddress2'];
$city = $_POST['fromcity'];
$zipcode = $_POST['fromzip'];
}
else
{
$address1 = $_POST['toaddress1'];
$address2 = $_POST['toaddress2'];
$city = $_POST['tocity'];
$zipcode =$_POST['tozip'];
}
//Assign Variables to the Session
$_SESSION['contactname'] = $contactname;
$_SESSION['contactemail'] = $contactemail;
$_SESSION['contactphone'] = $contactphone;
$_SESSION['address1']=$address1;
$_SESSION['address2']=$address2;
$_SESSION['city']= $city;
$_SESSION['zipcode'] = $zipcode;
?>
此时,我正在显示如下信息:\
<h1><?php echo $_SESSION['testvar']; ?></h1>
<h2>Travel Information</h2>
<h3>Please fill out this form:</h3>
<p>Direction of Travel: <?php echo $_SESSION['startlocation']; ?></p>
<p>LocationTo: <?php echo $_SESSION['city'] , $_SESSION['zipcode']; ?></p>
<p>Date: <?php echo $_SESSION['date']; ?></p>
<p>Time: <?php echo $_SESSION['time']; ?></p>
<p>Customer Name: <?php echo $_SESSION['contactname']; ?></p>
<p>Customer Email: <?php echo $_SESSION['contactemail']; ?></p>
<p>Customer Phone: <?php echo $_SESSION['contactphone']; ?></p>
<p>Address Information: <br />
<span>Address 1:</span><?php echo $_SESSION['address1']; ?><br />
<span>Address 2:</span><?php echo $_SESSION['address2']; ?><br />
<span>City:</span><?php echo $_SESSION['city']; ?><br />
<span>ZipCode:</span><?php echo $_SESSION['zipcode']; ?><br />
</p>
但是现在已经删除了数组中保存的起始位置和第一篇文章中的所有变量。您还可以看到我用来测试会话正在运行的testvariable,并且$_SESSION['testvar']
在所有文件上正确显示。我最初的代码设置如此$_SESSION['varname] = $_POST['varname'];
,但这产生了同样的问题。所以变量将转到下一页,但它不会继续到第三页。
非常感谢任何帮助。谢谢。
编辑:这可能是有用的信息:
Result from custinfo.php : bs2rrqoo5u1u5mjerkg54nkcb1 Array ( [startlocation] => From DIA [city] => Denver [zipcode] => [date] => 11/27/2012 [time] => 09:00 [fromaddress1] => [fromaddress2] => [fromcity] => [fromzip] => [toaddress1] => [toaddress2] => [tocity] => [tozip] => [contactname] => [contactemail] => [contactphone] => [address1] => [address2] => [testvar] => THIS IS A TEST [sameaddress] => 1 [billaddress1] => [billaddress2] => [billcity] => [billzip] => [ccnumber] => [ccexp] => [ccsc] => )
Result from custbilling.php : bs2rrqoo5u1u5mjerkg54nkcb1 Array ( [startlocation] => [city] => Aurora [zipcode] => 80017 [date] => [time] => [fromaddress1] => [fromaddress2] => [fromcity] => [fromzip] => [toaddress1] => [toaddress2] => [tocity] => [tozip] => [contactname] => Elijah Gartin [contactemail] => elijah.gartin@gmail.com [contactphone] => 3038804117 [address1] => 124 Test [address2] => [testvar] => THIS IS A TEST [sameaddress] => 1 [billaddress1] => [billaddress2] => [billcity] => [billzip] => [ccnumber] => [ccexp] => [ccsc] => )
答案 0 :(得分:1)
冲突会话会产生null
值。
尝试使用全局变量或通过持久数据结构传递值。
答案 1 :(得分:0)
会话变量将无法从http转换为https。
答案 2 :(得分:0)
问题出在服务器上。我必须将session.save_path = "/var/location"
添加到php.ini文件中。谢谢你们的努力。