2

HTML FORM Using POST method but php anytime "get" server request I am using php self link for login I can't find any solution for that let me know is there any syntax error or other bug

here is HTML code

<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>

here is code for 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>";
}

?>
HAROONMIND
  • 103
  • 7
  • If you view the source of the generated page what does the `action="..."` actually output? I ask because I had a similar issue - see here: http://stackoverflow.com/questions/26506168/why-is-serverrequest-method-always-get – LeonardChallis Jun 17 '16 at 14:15
  • 1
    check if there's any http redirects going on. post is not preserved over a normal 30x redirect. – Marc B Jun 17 '16 at 14:15
  • I check it here but it link to has no issue @LeonardChallis – HAROONMIND Jun 17 '16 at 15:30
  • When you open inspector/developer tools and view the Network panel, what do you see *for document requests (not CSS/images/etc)*. See any redirects? – LeonardChallis Jun 17 '16 at 15:31

0 Answers0