我遇到了PHP和会话问题。这是我的dictionary.php代码。PHP会话问题
<?php
if(!isset($_SESSION['auth'])){
$_SESSION['auth'] = 0;
}
if($_SESSION['auth'] == 0){
header("Location: index.php");
}
?>
因此,有这应该会话“身份验证”设置为0或1的index.php:
<?php
$msg = "";
//Password handler
if(!isset($_POST['password'])){
$password = "";
}else{
$password = $_POST['password'];
}
if(!isset($_SESSION['auth'])){
$_SESSION['auth'] = 0;
}
//Username handler
if(!isset($_POST['username'])){
$username = "";
}else{
$username = $_POST['username'];
if($username == "potato" && $password == "poteto"){
$_SESSION['auth'] = 1;
header("Location: dictionary.php");
}else{
$msg = "<br />
<font color=\"#FF0000\">Invalid username or password!</font><br />";
}
}
if($_SESSION['auth'] == 0){
header("Location: dictionary.php");
}
?>
(以上可能是不好的做法或东西,但我只是为了一个学校项目,我不希望其他人看到文件dictionary.php。)
index.php使用POST方法的形式发送$username
和$password
,以防万一你没有'尚未注意到。
当我输入登录信息“马铃薯”和“poteto”时,它将我重定向到dictionary.php,但立即将我引回index.php。我试过调整上面的代码,但没有运气。
如果有人需要我向他们展示此信息,那么我可以提供一个URL。
谢谢。
我在任何地方都看不到'session_start()'。首先解决它。阅读:http://php.net/manual/en/session.examples.basic.php –
“错误310(net :: ERR_TOO_MANY_REDIRECTS):有太多的重定向。” – Raymonf
@RBLXDev:你已经创建了一个重定向循环。这些对于排除故障来说不是那么简单,但是它有什么用处,现在你需要麻烦地拍摄它。 – hakre