我不知道为什么在刷新index.php后session_start()无法正常工作。
index.php页面应该显示“ echo $ _SESSION ['reg_code']; //用户输入的密钥密码,然后刷新此页面”
...但是不要显示出来。
///////////////////////index.php//////////////////////////
<?php
session_start();
if(isset($_POST['reg_code'])){
if (!empty($_POST['reg_code'])) {
$_SESSION ['reg_code'] =htmlspecialchars($_POST['reg_code']);
}
}
echo $_SESSION ['reg_code'];
?>
<form action="index.php" method="POST" enctype="multipart/form-data">
<center>
please enter your key pass :
<br>
<br>
<input placeholder="type here..." type="text" style="width: 400px; border-right: 8px; text-align: center;" name="reg_code"><br><br>
<input type="submit" name="submit" value="submit">
</center>
</form>
答案 0 :(得分:3)
请尝试这样。
<?php
session_start();
if(isset($_POST['reg_code']) && !empty($_POST['reg_code'])){
$_SESSION ['reg_code'] =htmlspecialchars($_POST['reg_code']);
}
if(isset($_SESSION ['reg_code']) && !empty($_SESSION ['reg_code'])){
echo $_SESSION ['reg_code'];
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<center>
please enter your key pass :
<br>
<br>
<input placeholder="type here..." type="text" style="width: 400px; border-right: 8px; text-align: center;" name="reg_code"><br><br>
<input type="submit" name="submit" value="submit">
</center>
</form>
我希望这会对您有所帮助。 谢谢。
答案 1 :(得分:0)
我认为您获得的是$ _SESSION ['reg_code'] == null。如果会话不包含任何值,则它将不起作用。只需尝试获取数据$ _POST ['reg_code']是否为空。
经过测试。起作用
<?php
session_start();
if(isset($_POST['reg_code']) && !empty($_POST['reg_code'])){
$_SESSION ['reg_code'] =htmlspecialchars($_POST['reg_code']);
echo $_SESSION ['reg_code'];
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<center>
please enter your key pass :
<br>
<br>
<input placeholder="type here..." type="text" name="reg_code"><br><br>
<input type="submit" name="submit" value="submit">
</center>
</form>