【问题标题】:can not get the $_POST value in php ,but $_GET is ok无法在 php 中获取 $_POST 值,但 $_GET 可以
【发布时间】:2016-02-24 13:56:20
【问题描述】:

我使用 PHP 5.6 和 PHPstorm 10。

html 代码如下。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
</head>
<body>
    <form action="hello.php" method="post">
        <input type="text" name="blabla">
        <input type="submit">
    </form>
</body>
</html>

PHP 代码如下。

<?php
    echo $_POST["blabla"];
?>

但是如果我将方法更改为GET。 这将是工作。但我无法获取帖子值。

然后我安装了WAMP Server。当只是使用WAMP Server访问时,它成功了。为什么?为什么我不能使用PHPStorm获取帖子值。

【问题讨论】:

  • 很奇怪。应该可以工作...尝试$_REQUEST 而不是$_POST
  • 改成$_GET后,看到查询字符串中的数据了吗?
  • @PhiterFernandes 这不是解决方案。
  • 我知道先生,这就是为什么它不是答案,而是评论。
  • .htaccess 或 httpd.conf 中有 RewriteRule 吗?

标签: php jetbrains-ide


【解决方案1】:

您需要通过以下方式检查“请求类型”:-

$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
    // Method is POST
    echo "post";
    $data = isset($_POST["blabla"]) ? $_POST["blabla"] : 'notset';
    echo $data;   // print data
} elseif ($method == 'GET') {
    // Method is GET
    echo "get";
} else {
    // Method unknown may be put or delete
     echo "unknown";
}

希望对你有帮助:)

【讨论】:

  • 返回这个。已弃用:自动填充 $HTTP_RAW_POST_DATA 已弃用,将在未来版本中删除。为避免此警告,请在 php.ini 中将“always_populate_raw_post_data”设置为“-1”,并改用 php://input 流。在第 0 行的未知中警告:无法修改标头信息 - 标头已在第 0 行的未知中发送 postnotset
  • 只是一张支票。但我仍然无法获得帖子值
【解决方案2】:

删除表单的method = "post"

PHP 代码如下。

<?php
    echo $_REQUEST["blabla"];
?>

【讨论】:

    猜你喜欢
    • 2014-02-24
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多