HTML表格随时使用POST方法但是php" get"服务器请求

时间:2016-06-17 14:13:40

标签: php html login login-control

HTML表单使用POST方法,但随时随地使用php" get"服务器请求 我使用php自我链接登录我无法找到任何解决方案,让我知道有任何语法错误或其他错误

这是HTML代码

<body>
<div style="width:90px;height:33px; float:right;margin-top:20px;background-color: #F8F8F8;border-radius: 5px; padding:10px; margin-right: 70px; ">
        <a href="../admin/admin.php" style="margin-top:10px; position:absolute;color: rgb(98, 98, 98);font-weight: bold;font-size:16px">Admin login</a>

</div>
<!-- Header -->
<div id="main">

        <!-- Logo + Top Nav -->
        <div class="logo" style="width:300px;height:150px;left: 85px;position: relative;">
                <img src="../../gallery/icon-logo.png" style=" width: 302px;height: 180px;"/>
        </div>
        <form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  style="height:350px;margin-top:70px; padding-top: 20px;opacity: 0.9;">
        <div align="center" style="margin-top:50px">

                        <table width="150" border="1">
                                <tr>
                                        <td>Username</td>
                                        <td><label>
                                                        <input type="text" name="uname" required/>
                                                </label></td>
                                </tr>
                                <tr>
                                        <td>Password</td>
                                        <td><label>
                                                        <input type="password" name="pword" required/>
                                                </label></td>
                                </tr>
                                <tr>
                                        <td colspan="2" align="center"><input type="submit" name="submit"  style="width:120px;height: 40px;" /></td>
                                </tr>
                        </table>



        </div>
        </form>
</div>
<!-- End Container -->

</body>
</html>

这是php的代码

<?php

echo "<script>alert('I am here');</script>";

if($_SERVER["REQUEST_METHOD"] == "POST") {
        error_reporting(E_ALL ^ E_NOTICE);
        session_start();
        $session_expiration = time() + 3600 * 12; // +2 days
        session_set_cookie_params($session_expiration);
        echo "<script>alert('I am here in post');</script>";
        $employee = $_POST['uname'];
        $password = $_POST['pword'];

        include("../config/config.php");

        $login = mysqli_query($link, "SELECT * FROM  admin WHERE (username = '" . $employee . "') and (password  = '" . $password . "')");

        // Check username and password match
        if (mysqli_num_rows($login) == 1) {
                // Set username session variable
                $_SESSION['user'] = $employee;
                $_SESSION['login'] = 1;
                // Jump to secured page
                header("Location:../default/index.php");
                exit;
        } else {
                // Jump to login page
                echo " <div style=' padding:5px; color:red;' ><h4 style='color=#D00000;'>Invalid UserName or Password</h4></div>";


        }
}else if($_SERVER["REQUEST_METHOD"] == "GET") {
        echo "<script>alert('I am GET');</script>";
}

?>

0 个答案:

没有答案