dtpa98038 2017-07-08 12:58
浏览 91
已采纳

POST表单不与PHP一起使用,与Postman合作

This is login code with session. Iam using bootstrap.The code is not redirecting to index.html, when I test it in Postman it works but it is not working in this bootstrap template. I didnt get the reason? Please Help

<?php

if($_SERVER["REQUEST_METHOD"]=="POST") {
    $email=$_POST["email"];
    $password=$_POST["password"];

    $sql = "SELECT * FROM login where email='$email' and password='$password'";

    $result = mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
    $count = mysqli_num_rows($result);

    if ($count>0) {

        // output data of each row
        if($row['admin_role']==1) {
            //$_SESSION["email"]=$email;
            //$_SESSION["id"]=$row['user_id'];

            //echo "Login successfull";

            header('Location: index.html');
            exit; 
        }
    } else {
        echo "0 results";
    }
}

?>


<div class="row">
    <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
        <div class="login-panel panel panel-default">
            <div class="panel-heading"> Admin Log in</div>
            <div class="panel-body">
                <form role="form">
                    <fieldset>
                        <div class="form-group">
                            <input class="form-control" placeholder="E-mail" name="email" type="email" autofocus="">
                        </div>
                        <div class="form-group">
                            <input class="form-control" placeholder="Password" name="password" type="password" value="">
                        </div>
                        <div class="checkbox">
                            <label>
                                <input name="remember" type="checkbox" value="Remember Me">Remember Me
                            </label>
                        </div>
                        <a href="" class="btn btn-primary">Login</a>
                    </fieldset>
                </form>
            </div>
        </div>
    </div><!-- /.col-->
</div><!-- /.row --> 
  • 写回答

4条回答 默认 最新

  • doujie2356 2017-07-08 13:01
    关注

    Your form is a GET form, you need to set method="POST" on your <form> tag.

    Other than that, your code is very vulnerable, you should be hashing the passwords in your database, and you should use PDO as it's more secure and you should also use prepared statements and turn off emulated ones with that.

    Currently, your code is vulnerable to SQL injection, one of the most basic but the most dangerous security threats for a web application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊