这个网页有一个直接的循环,有人可以帮助我我的代码

时间:2015-06-07 15:17:15

标签: php mysql

当我尝试加载页面的内容时,会显示"此网页有一个重定向循环"。有人可以帮助我吗?我遇到了麻烦而且我不知道该怎么做以及我的错误。

AdminLogin.php

<?php
require 'db.php';
$msg='';
session_start();
if(!empty($_SESSION['login_user']) && isset($_SESSION['login_user']))
{
    header("Location: AdminHome.php");
}

if(!empty($_POST['username']) && isset($_POST['username']) && !empty($_POST['password']) && isset($_POST['password']))
{
    $username = mysqli_real_escape_string($connection, $_POST['username']);
    $password = mysqli_real_escape_string($connection, $_POST['password']);
    $sql = mysqli_query($connection, "SELECT username FROM admin WHERE username = '".$username."' AND password ='".$password."'");
    $count = mysqli_num_rows($sql);

    if($count == 1)
    {

        $_SESSION['login_user'] = $username;
        header("Location: AdminHome.php");
        exit;
    }
    else
    {
         $msg='Username and Password didnt match';
    }

    mysqli_close($connection);
}
?>
<html>
<head>
    <meta charset="utf-8">
<title>Login</title>
<!--<link rel="stylesheet" href="css/bootstrap.css">-->
<!--<link rel="stylesheet" href="css/customAdmin.css">-->
</head>
<body>
    <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
          <div class="container">
              <div class="navbar-header">
                  <p class="systemName">Pawn Broking Management System</p>
              </div>
          </div>            
    </nav>
    <br><br><br><br><br><br><br><br>
    <form class="form-horizontal" method="post">
        <center><img src="logoAdmin.png" class="imageLogin"></center>
        <hr class="hr-custom">
        <br>
        <center><input type="text" name="username" class="form-control-custom" id="inputEmail3" placeholder="Username" autocomplete="off"></center> <br>
        <center><input type="password" name="password" class="form-control-custom" id="inputPassword3" placeholder="Password" autocomplete="off"></center> <br>
        <center><button type="submit" class="btn btn-custom" href="">Login</button></center><br>
        <span class='msg'><?php echo $msg; ?></span>
        <hr class="hr-custom2">
    </form>
    <footer>
        <center> Copyright 2015 - PBMS. All rights reserved.</center>
    </footer>
</body>
</html>

AdminHome.php

<?php
include 'db.php';
session_start();
$user_check = $_SESSION['login_user'];
$sql = mysqli_query($connection, "SELECT username FROM admin WHERE username = '".$user_check."'");

$row = mysqli_fetch_assoc($sql);
$login_session = $row['username'];
if(!isset($login_session)){
    mysql_close($connection);
    header("Location: AdminLogin.php");
}

?>
<html>
<head>
  <meta charset="utf-8">
  <title>Home</title>
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="css/customAdmin.css">
  <link href="css/simple-sidebar-admin.css" rel="stylesheet">
</head>
<body>


<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <p class="systemName">Pawn Broking Management System
                  <a href="#menu-toggle" class="btn btn-default" id="menu-toggle">Toggle Menu</a>
                </p>
            </div>

               <div class="logout" align="right"><a href="Logout.php" class="textLogout">Logout</a> </div>
        </div>
    </nav>

<br><br><br>

    <div id="wrapper">


            <div id="sidebar-wrapper">
                <ul class="sidebar-nav">
                    <br><br><br><br>  
                    <li>
                        <a class="visited">Home</a>
                    </li>
                    <li>
                        <a href="#">Registered Pawnshop</a>
                    </li>
                    <li>
                        <a href="#">Registration Request</a>
                    </li>
                    <li>
                        <a href="#">Delete Pawnshop Account</a>
                    </li>



                </ul>
            </div>

            <div id="page-content-wrapper">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-12">




                  <form class="formFont">
                    <div class="container">
                        <div class="row">
                           <h1 class="welcomeText">Welcome Admin!</h1>
                           <center><img src="logoAdmin.png" class="image"></center>
                        </div>
                    </div>

                 </form>



                        </div>
                    </div>
                </div>
            </div>

            <script src="js/custom.js"></script>
            <script src="js/jquery.js"></script>
            <script src="js/bootstrap.min.js"></script>
            <script>
              $("#menu-toggle").click(function(e) {
                  e.preventDefault();
                  $("#wrapper").toggleClass("toggled");
              });
            </script>


    <footer>
       <center> Copyright 2015 - PBMS. All rights reserved. </center>
    </footer>
</body>
</html>

Logout.php

<?php
session_start();
if(session_destroy())
{
header("Location: AdminLogin.php"); 
}
?>

0 个答案:

没有答案