此页面无效 本地主机将您重定向了太多次。 尝试清除您的cookie。 ERR_TOO_MANY_REDIRECTS 这是主要错误,我不知道是什么问题,我正确编写了我的代码,请帮助我。 我已经提交了html和php代码,如果有人知道主要问题是什么,请与我分享。
<?php
session_start();
if (isset($_SESSION['admin'])) {
header('location:admindash.php');
}
else{
header('location:login.php');
}
include('header.php');
?>
<body background="../bgimage.jpg">
<div class="container">
<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info" >
<div class="panel-heading">
<div class="panel-title text-center">Login for Admin</div>
<div style="float:right; font-size: 80%; position: relative; top:-10px"><a href="#"></a></div>
</div>
<div style="padding-top:30px" class="panel-body" >
<div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
<form id="loginform" class="form-horizontal" role="form" method="post" action="login.php">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="login-username" type="text" class="form-control" name="uname" value="" placeholder="username or email">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="login-password" type="password" class="form-control" name="password" placeholder="password">
</div>
<div class="input-group">
<div class="checkbox">
<label>
<input id="login-remember" type="checkbox" name="remember" value="1"> Remember me
</label>
</div>
</div>
<div style="margin-top:10px" class="form-group">
<!-- Button -->
<div class="col-sm-12 controls">
<input id="btn-login" class="btn btn-success" type="submit" name="submit" value="login">
</div>
</div>
<div class="form-group">
<div class="col-md-12 control">
</div>
</div>
</form>
</div>
</div>
</body>
</html>
<?php
include('../dbcon.php');
if (isset($_POST['submit'])) {
$username = $_POST['uname'];
$password = $_POST['password'];
$qry = "SELECT * FROM `login` WHERE `uname`='$username' AND `password`='$password' ";
$run = mysqli_query($dbcon,$qry);
$row = mysqli_num_rows($run);
if ($row<1)
{
?>
<script type="text/javascript">alert('username and password does not match');
window.open('login.php','_self')
</script>
<?php
}
else{
$data = mysqli_fetch_assoc($run);
$id = $data['id'];
$_SESSION['admin'] = $id;
header('location:admindash.php');
}
}
?>
答案 0 :(得分:3)
您的登录页面正在将重定向至自身:
if (isset($_SESSION['admin'])) {
header('location:admindash.php');
}
else{
header('location:login.php'); // here
}
每次页面加载时都会执行 。这导致无休止的重定向周期。由于用户已经在登录页面上,因此您无需将其发送到登录页面。只需完全删除else
块:
if (isset($_SESSION['admin'])) {
header('location:admindash.php');
}