简体   繁体   English

本地主机的 ERR_TOO_MANY_REDIRECTS

[英]ERR_TOO_MANY_REDIRECTS for localhost

I have created two separate files for login screen.我为登录屏幕创建了两个单独的文件。 one is loginpage.php where html code is there and another one is login.php which contains backend code.一个是 loginpage.php 其中 html 代码在那里,另一个是 login.php 包含后端代码。 Both the codes were running fine and were giving proper output.两个代码都运行良好,并且给出了正确的 output。 But now it is not working, whenever I try to load the page it is showing this error-但是现在它不起作用,每当我尝试加载页面时,它都会显示此错误-

This page isn't working localhost redirected you too many times.此页面无法正常工作 localhost 将您重定向了太多次。 Try clearing your cookies.尝试清除您的 cookies。 ERR_TOO_MANY_REDIRECTS. ERR_TOO_MANY_REDIRECTS。

I have almost tried doing everything like clearing cookies and cached files, changing proxy server settings, running cmd commands.我几乎尝试过清除 cookies 和缓存文件、更改代理服务器设置、运行 cmd 命令等所有操作。

re-installed xampp.重新安装 xampp。

But still it is showing the same thing, and I am unable to find the problem in my code.但它仍然显示相同的东西,我无法在我的代码中找到问题。

at first i was displaying all the errors using alert message.起初我使用警报消息显示所有错误。 but that also i have changed and storing it in an array and display in the form.但是我也已经更改并将其存储在数组中并以表格形式显示。 please help请帮忙

LOGINPAGE.PHP LOGINPAGE.PHP

   <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Task Manager | Log in</title>
    
      <!-- Google Font: Source Sans Pro -->
      <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
      <!-- Font Awesome -->
      <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
      <!-- icheck bootstrap -->
      <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
      <!-- Theme style -->
      <link rel="stylesheet" href="../dist/css/adminlte.min.css">
    </head>
    <body class="hold-transition login-page">
      <div class="login-box">
        <div class="login-logo">
          <p><b>Task Manager</b></p>
        </div>
        <div id="box">
          <!-- /.login-logo -->
          <div class="card">
            <div class="card-body login-card-body">
              <p class="login-box-msg">Sign in to start your session</p>
              
    
              <form action="login.php" method="post" id="login-form">
                <div class="input-group mb-3">
                  <input type="email" class="form-control" placeholder="EmailID" id="email" name="email" required>
                  <div class="input-group-append">
                    <div class="input-group-text">
                      <span class="fas fa-user-alt"></span>
                    </div>
                  </div>
                </div>
                <div class="input-group mb-3">
                  <input type="password" class="form-control" placeholder="Password" id="password" name="password" required>
                  <div class="input-group-append">
                    <div class="input-group-text">
                      <span class="fas fa-lock"></span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                      <select class="form-control select2bs4" name="role" id="role">
                        <option selected="selected">-select role-</option>
                        <option>ADMIN</option>
                        <option>EMPLOYEE</option>
                      </select>
                </div>
                <div class="row">
                  <div class="col-8">
                    <div class="icheck-primary">
                      <input type="checkbox" id="remember">
                      <label for="remember">
                    Remember Me
                  </label>
                    </div>
                  </div>
                  <!-- /.col -->
                  <div class="col-4">
                    <button type="submit" class="btn btn-success btn-block" id="btn_submit" name="btn_submit"  >Sign In</button>
                  </div>
                  <!-- /.col -->
                </div>
              </form>
              <p class="mb-1">
                <br/>
                <a href="forgotpassword.html">I forgot my password</a>
              </p>
            </div>
            <div id="error">
              <?php
              include 'login.php';
              if(empty($errormsg))
              {
                foreach($errormsg as $value)
                {
                  echo "$value";
                }
              }
              ?>
            </div>
            <!-- /.login-card-body -->
          </div>
        </div>
      </div>`
      
      <!-- /.login-box -->
    <!-- jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
      <!-- Bootstrap 4 -->
    <script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
      <!-- AdminLTE App -->
    <script src="../dist/js/adminlte.min.js"></script>
    </body>
    </html>

This is the backend code for login screen这是登录屏幕的后端代码

LOGIN.PHP LOGIN.PHP

<?php
include('db_connection.php');
session_start();

if (!(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] != '')) {
    header("location:loginpage.php");
}
if(isset($_SESSION["employee_login"])){
    header("location:employee_dash.php");
} 
if(isset($_POST['btn_submit']))
{
    $email=$_POST['email'];
    $password=md5($_POST['password']);
    $role=strtolower($_POST['role']);

    if(empty($email)){
        $errormsg[]="Please enter email";
    } else if(empty($password)){
        $errormsg[]="Please enter password";
    } else if(empty($role)){
        $errormsg[]="Please select a role";
    } else if($email && $password && $role) {
        try {
            $query="SELECT email,password,role FROM `employee` WHERE email=? && password=? && role=?";
            $stmt = mysqli_prepare($conn,$query);
            
            mysqli_stmt_bind_param($stmt,'sss',$email,$password,$role);
            mysqli_stmt_bind_result($stmt,$email,$password,$role);
            mysqli_stmt_execute($stmt);
            $result=mysqli_stmt_get_result($stmt);
            while($row = mysqli_fetch_assoc($result)) {
                $dbemail=$row['email'];
                $dbpassword=$row['password'];
                $dbrole=$row['role'];
            }

            if(mysqli_num_rows($result)>0) {
                if($email==$dbemail && $password==$dbpassword && $role==$dbrole) {
                    switch($dbrole) {
                        case "admin":
                            $_SESSION["admin_login"]=$email;
                            header("refresh:1;dashboard.php");
                            break;
                            
                        case "employee":
                            $_SESSION["employee_login"]=$email;
                            header("refresh:1;employee_dash.php");
                            break;
    
                        default:
                        $errormsg[]="Invalid Role";
                    }
                } else {
                    $errormsg[]="Wrong Email or Password or Role"; 
                }
            } else {
                $errormsg[]="Records Not Found";
            }
        } catch(Exception $e) {
            echo $e->errorMessage();
            mysqli_stmt_close($stmt);
        }
    } else {
        $errormsg[]="Enter the crendentials";
    }
}
?>


You are redirecting to loginpage.php from the same page without destroying your session first, then it will keep redirecting from loginpage to loginpage as infinite loop.您正在从同一页面重定向到loginpage.php而不会首先破坏您的 session,然后它将继续从loginpage重定向到loginpage作为无限循环。

try to check if session is populated and destroy it, instead of:尝试检查 session 是否已填充并销毁它,而不是:

if (!(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] != '')) 
{
    header("location:loginpage.php");
}

You destroy any session already exit like:您销毁任何 session 已经退出,如:

if (!(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] != '')) 
{
    session_destroy();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载资源:net :: ERR_TOO_MANY_REDIRECTS - Failed to load resource: net::ERR_TOO_MANY_REDIRECTS 调用 res.redirect 后出现 ERR_TOO_MANY_REDIRECTS - ERR_TOO_MANY_REDIRECTS after calling res.redirect KoaJS ctx.redirect()在Chrome中导致ERR_TOO_MANY_REDIRECTS - KoaJS ctx.redirect() causing ERR_TOO_MANY_REDIRECTS in Chrome 从带有脚本标签的已发布 Google 表格中读取数据会引发 `net::ERR_TOO_MANY_REDIRECTS` 错误 - Reading data from a published Google Sheets with a script tag throws a `net::ERR_TOO_MANY_REDIRECTS` error 尝试通过使用 Selenium 和 Python 的框架和 Javascript 的网页登录时出现 ERR_TOO_MANY_REDIRECTS 错误 - ERR_TOO_MANY_REDIRECTS error while trying to login through a webpage that uses frames and Javascript using Selenium and Python 如何修复HTTP中的“重定向过多”错误 - How to fix “Too Many Redirects” error in HTTP JQuery 中的 ERR_ABORTED 429(请求过多) - ERR_ABORTED 429 (Too Many Requests) in JQuery NextJs 重写产生 localhost redirected you too many times 错误 - NextJs rewrites produce localhost redirected you too many times error 我的网站在Chrome中生成了太多重定向错误。 为什么会这样,我该如何解决? - My website is generating too many redirects errors in chrome. Why is this and how can I fix it? net :: ERR_ABORTED 429(请求过多),访问权限...被CORS策略阻止 - net::ERR_ABORTED 429 (Too Many Requests), Access… blocked by CORS policy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM