首页 > 解决方案 > php标头更改后Javascript动画不起作用

问题描述

当我在 localhost/project/login.php 中时,我的 javascript 动画可以工作,但是在检查无效的用户名/密码后,我的标题将变成 localhost/project/login.php?login=error 我的 javascript 动画将停止工作。请帮忙。

这是我的PHP。如果用户名/密码不正确,它会验证我的登录页面并显示错误消息。

<?php
    if (!$link){
        die("Could not connect: ".mysql_error());
        exit();
    } else {
        $result = mysqli_query($link, "select * from users where username = '$username' and password = '$password'");

        $row = mysqli_fetch_array($result);
        if($row['username'] == $username && $row['password'] == $password){
            //echo "Login Success!! Welcome ";
            if ($row['role'] == 0){
                header('Location: lecturer.php');
            } else if ($row['role'] == 1) {
                header('Location: student.html');
            }
        }else{
            header('Location: login.php?login=error');
        }
    }

?>

这是我的项目的 HTML。

<!DOCTYPE html>
<html>

<head>
    <title>Login</title>
    <link rel="stylesheet" type="text/css" href="projectCss/logincss.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.min.js"></script>
</head>
<body>
    <div class="page">
        <div class="page-overlay"></div>
        <!-- <img style="margin-left: 160px;" src="img/logo.png" width="1080px"> -->
        <h1
        style="color: white;text-shadow: 1px 1px 2px black, 0 0 1px whitesmoke, 0 0 5px white;font-family:cursive;font-size: 40px;margin-left: 320px;">
    UCSI Consultation Management System</h1>
    <div class="container">
        <div class="left">
            <div class="login">Login</div>
            <div class="eula">"We must use time as a tool, not as a couch."
                <br>
                <br>
                <br>
                <div style="text-align: right;">- John F.Kennedy</div>
            </div>
        </div>
        <div class="right">
            <svg viewBox="0 0 320 300">
                <defs>
                    <linearGradient inkscape:collect="always" id="linearGradient" x1="99" y1="193.49992" x2="99"
                    y2="193.49992" gradientUnits="userSpaceOnUse">
                    <stop style="stop-color:#ff2600;" offset="0" id="stop876" />
                    <stop style="stop-color:#1c227a;" offset="1" id="stop878" />
                </linearGradient>
            </defs>
            <path
            d="m 40,120.00016 239.99984,-3.2e-4 c 0,0 24.99263,0.79932 25.00016,35.00016 0.008,34.20084 -25.00016,35 -25.00016,35 h -239.99984 c 0,-0.0205 -25,4.01348 -25,38.5 0,34.48652 25,38.5 25,38.5 h 215 c 0,0 20,-0.99604 20,-25 0,-24.00396 -20,-25 -20,-25 h -190 c 0,0 -20,1.71033 -20,25 0,24.00396 20,25 20,25 h 168.57143" />
        </svg>
        <form action="loginprocess.php" method="POST">
            <div class="form">
                <label for="username">Username</label>
                <input type="text" id="user" name="user" required>
                <label for="password">Password</label>
                <input type="password" id="pass" name="pass" required>
                <input type="submit" id="submit" value="login">
            </div>
            <?php
            $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
            if(strpos($fullUrl, 'login=error') == true){
             echo "<p class='error'>Invalid username/password!</p>";
             exit();
         }
         ?>
     </form>
 </div>
</div>
</div>
</body>
<script type="text/javascript" src="projectJS/login.js"></script>
</html>

标签: javascriptphphtml

解决方案


推荐阅读