Php 会话_start()在保存变量时引发错误

Php 会话_start()在保存变量时引发错误,php,html,Php,Html,我有以下表格: <html> <head> </head> <body> <form method=post action="submit.php"> <!-- If the user goes to a different page or refreshes this page it and returns to this page within 2 hours the value that was originally

我有以下表格:

<html>
<head>
</head>

<body>
<form method=post action="submit.php">
<!-- 


If the user goes to a different page or refreshes this page it and returns to this page within 2 hours the value that
was originally entered should populate in the respective textbox,radio groups which is not happening...

 -->
    <input type=text value="<?php echo $_SESSION['saveit'][0]; ?>" name="first" />

    <input type=radio value="A" name="acct" <?php echo ($_SESSION['saveit'][1] == A) ? "checked" : "" ?> /> A
    <input type=radio value="B" name="acct" <?php echo ($_SESSION['saveit'][1] == B) ? "checked" : "" ?> /> B

    <input type=radio value="A" name="birt" <?php echo ($_SESSION['saveit'][2] == A) ? "checked" : "" ?> /> A
    <input type=radio value="B" name="birt" <?php echo ($_SESSION['saveit'][2] == B) ? "checked" : "" ?> /> B

    <input type=submit value="submit" />
</form>
<?php
//echo to see what those values are
echo $_SESSION['saveit'][0];
echo "<BR>";
echo $_SESSION['saveit'][1];
echo "<BR>";
echo $_SESSION['saveit'][2];
echo "<BR>"
?>
</body>
</html>


在第一页上调用会话_start()失败。必须在使用会话变量的所有页面上调用它,并且应该在调用其他任何内容之前调用它


实际上,您从未使用表单启动页面上的会话,因此您设置的任何值实际上都没有被设置。

侧注:
$f=isset($first)$第一:空$first总是设置好的,你在之前分配了它几行…也许你的意思是
isset($\u POST['first'])
?我这样做是为了防止任何XSS攻击。什么?我看不出XSS攻击与检查是否设置了索引有什么关系…
$first=trim(strip_标记(stripslashes($_POST['first']))
阻止用户在文本框中输入脚本,所以我在使用它之前清理所有输入?我不是说这个,但为什么不在访问它之前检查是否设置了$\u POST,为什么不检查是否设置了声明的变量。我的意思是
if(isset($\u POST['first']){//do your custom escaping}
你在这方面实际上是正确的。谢谢现在我该怎么做才能让它只停留3个小时呢?@SiKni8你必须给时间打电话()并将其存储在会话变量中,然后使用控制结构检查该时间的值并执行适当的操作——在这种情况下,您将取消设置特定会话变量,或者可能完全销毁会话并启动新的会话。
<?php
session_start();

//Get the value from form
$first = trim(strip_tags(stripslashes($_POST['first'])));
$acct = trim(strip_tags(stripslashes($_POST['acct'])));
$birt = trim(strip_tags(stripslashes($_POST['birt'])));

$f = isset($first) ? $first : null;
$a = isset($acct) ? $acct : null;
$b = isset($birt) ? $birt : null;

$savearray = array($f,$a,$b);

$_SESSION['saveit'] = $savearray;

//save the value in each individual session (Not using it as I need to save multiple values in ONE session)
//$_SESSION['textbox1'] = isset($first) ? $first : null;
//$_SESSION['radiogroup1'] = isset($acct) ? $acct : null;
//$_SESSION['radiogroup2'] = isset($birt) ? $birt : null;

//set the cookie for each session with the value for 2 hours TTL
//CORRECT syntax to save the ONE session with multiple variable into cookie to be used for upto 2 hours MAX.
//setcookie("textbox1", $first, time()+(3600*2));

//echo test to see what the values are
echo $_SESSION['saveit'][0];
echo "<BR>";
echo $_SESSION['saveit'][1];
echo "<BR>";
echo $_SESSION['saveit'][2];
echo "<BR>";

echo "<a href='http://www.interfaithmedical.com/checksite/testFolder/form.php'>GO TO THE FORM PAGE</a>";
?>