【问题标题】:$_POST method not working although $_Get work Fine尽管 $_Get 工作正常,但 $_POST 方法不起作用
【发布时间】:2018-04-27 22:04:00
【问题描述】:
<?php
//    include_once '../include/user_functions.php';
    if(isset($_POST['btn'])){
        $data=$_POST['frm'];
//        user_login($data);
        var_dump($_POST['frm']);
    }
?>
<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <meta name="keyword" content="FlatLab, Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">
    <link rel="shortcut icon" href="img/favicon.html">
    <title>FlatLab - Flat & Responsive Bootstrap Admin Template</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/bootstrap-reset.css" rel="stylesheet">
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet" />
</head>

  <body class="login-body">

    <div class="container">

      <form class="form-signin" action="" method="post">
        <h2 class="form-signin-heading">login now</h2>
        <div class="login-wrap">
            <input type="text" class="form-control" placeholder="username" name="frm[username]"autofocus>
            <input type="password" class="form-control" name="frm[password]" placeholder="password">
            <label class="checkbox">
                <input type="checkbox" value="remember-me">remember me
                <span class="pull-right"> <a href="#"> forget password?</a></span>
            </label>
            <button class="btn btn-lg btn-login btn-block" value="btn-button" name="btn" >login</button>

        </div>

      </form>

    </div>


  </body>
</html>
  1. 当我更改表单方法以使其正常工作时。

  2. 当我使用浏览器网络选项卡标题时,表单数据具有价值

  3. 当我将if(isset($_POST['btn'])) 更改为vardump($_POST) 时,它始终返回array(0) { }

  4. 我在 xampp 上运行 php

upload_max_filesize=130M post_max_size=130M

需要任何其他信息吗?

【问题讨论】:

  • @Martin 我将其更改为输入 type="sumbit"。它对我不起作用
  • &lt;input type='submit'&gt; 是你想要的(你的评论中有错字)
  • 也可以试试if ($_SERVER['REQUEST_METHOD'] == 'POST') { print "posted ok"; }
  • this question 对您有帮助吗?
  • @Martin 代码重新发布正常

标签: php


【解决方案1】:

认为您的问题是您使用了Content Security Policy 标头"Upgrade Insecure Requests",当在普通(不安全)HTTP 上使用时,它有几个minor bugs

因为您的localhost 是 HTTP,这可能会中断 POST 数据,因为“升级不安全请求”标头正试图发送到 HTTPS 地址,因此可能会阻止(剥离)发现无法到达时发布数据。

请尝试禁用“升级不安全请求”标头(并可能清除浏览器缓存),看看这是否对您的问题有帮助?

这也可能取决于所使用的浏览器,因为 CSP 目前仅在某些浏览器上。

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 2014-12-12
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多