无法访问获取 dBase 数据。登录页面不断循环回到同一页面

Unable to access fetch dBase data. The login page keep looping back to thesame page

每次我尝试通过 webhost/adminlogin.php 登录时,我都会被重定向回同一页面。有什么我忘了补充的吗?谢谢你的帮助。下面是我的脚本

这是我的adminlogin.php

<?php session_start(); if(isset($_SESSION[ 'admin_login'])) header( 'location:admin_homepage.php'); ?>

<!DOCTYPE html>
<html>

<head>
  <noscript>
    <meta http-equiv="refresh" content="0;url=no-js.php">
  </noscript>
  <meta charset="UTF-8">
  <title>Admin Login - Online Banking</title>

  <link rel="stylesheet" href="newcss.css">
</head>
<?php include 'header.php'; ?>

<div class='content'>
  <div class="user_login">
    <form action='' method='POST'>
      <table align="center">
        <tr>
          <td><span class="caption">Admin Login</span>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <hr>
          </td>
        </tr>
        <tr>
          <td>Username:</td>
        </tr>
        <tr>
          <td>
            <input type="text" name="uname" required>
          </td>
        </tr>
        <tr>
          <td>Password:</td>
        </tr>
        <tr>
          <td>
            <input type="password" name="pwd" required>
          </td>
        </tr>
        <tr>
          <td class="button1">
            <input type="submit" name="submitBtn" value="Log In" class="button">
          </td>
        </tr>
      </table>
    </form>
  </div>
</div>

<?php include 'footer.php'; ?>
<?php include '_inc/dbconn.php'; if(!isset($_SESSION[ 'admin_login'])){ if(isset($_REQUEST[ 'submitBtn'])){ $sql="SELECT * FROM admin WHERE id='1'" ; $result=mysql_query($sql); $rws=m ysql_fetch_array($result); $username=m ysql_real_escape_string($_REQUEST[
'uname']); $password=m ysql_real_escape_string($_REQUEST[ 'pwd']); if($username==$rws[8] && $password==$rws[9]) { $_SESSION[ 'admin_login']=1; header( 'location:admin_hompage.php'); } else header( 'location:adminlogin.php'); } } else { header(
'location:admin_hompage.php'); } ?>

我认为您的脚本可能存在一些问题。一个明显的问题是,在发送脚本底部的 headers 之前,您正在输出 html 内容。

HTTP headers 必须在任何其他内容之前发送到客户端。

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

我建议除非您需要继续处理。您将所有登录代码移至脚本顶部并调用 'exit()';在您将 headers 发送到客户端以防止任何进一步处理或将内容发送到客户端之后。