【发布时间】:2015-12-11 17:07:41
【问题描述】:
我的代码有什么问题?我在同一个文件夹中有两个文件:index.php 和 pass.txt:
这是 pass.txt:
qwerty
这是 index.php:
<?php
$password=file_get_contents('pass.txt');
session_start();
if (isset($_SESSION['timeout'])) {
if ($_SESSION['timeout'] + 10 < time()) {
session_destroy(); } }
else {
$_SESSION['pass']="" ; $_SESSION['timeout']=time(); }
if (isset($_POST["pass"])) {
$_SESSION['pass']=$_POST['pass'] ;
}
if($_SESSION['pass'] == $password) {
echo 'you are logged in';
} else {
echo'<form method="POST" action="">
<input type="password" name="pass">
</form>';
}
?>
问题:当我在输入字段中写“qwerty”并提交时,它不显示“您的啤酒已登录”
这只是一个用于进一步开发的语法问题,并非旨在保护任何东西。
其他已回答的问题并没有解决我的问题。
【问题讨论】:
-
有什么问题?您没有在问题中说明这一点。
-
以为是理解,修改,抱歉,XXX
-
你在
echo($_SESSION['pass']);中得到qwerty吗? -
你在页面顶部有
session_start(),对吗? -
是的,我在问题中添加了完整代码
标签: php file post text flat-file