gpt4 book ai didi

php - $_POST 在 php5.6 中为空

转载 作者:搜寻专家 更新时间:2023-10-31 21:52:15 24 4
gpt4 key购买 nike

在堆栈溢出中提交表单后,我尝试了几乎所有与空 $_POST 相关的解决方案,但没有一个解决了我的问题。我正在使用 wamp 服务器并使用 phpstorm。

  • 更改了 php.ini 中 post_max_size 和 upload_max_filesize 的值
  • $_GET 工作正常
  • 尝试使用其他ide和编辑器
  • isset 返回 false
  • var_dump 显示数组为空
  • 将 method="post"更改为 method="POST"
    我的代码:
    主.html

    <html>
    <body>
    <form action="welcome.php" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>
    </body><br>
    </html>

    欢迎.php

    <html>
    <body>
    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>
    </body>
    </html>`

错误-

欢迎

Notice: Undefined index: name in
C:\Users\user\PhpstormProjects\tryphp\welcome.php on line 4

您的电子邮件地址是:

Notice: Undefined index: email in
C:\Users\user\PhpstormProjects\tryphp\welcome.php on line 5

最佳答案

通过快速测试,您的代码在我的服务器上正常运行。

运行 PHP 配置文件 (/etc/php5/apache2/php.ini) 我发现这些项目可能值得研究

; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
;enable_post_data_reading = Off

所以进入你的 php.ini 并搜索 enable_post_data_reading,如果你没有找到它,请手动将其放入(通常在文件末尾)并确保它已打开

enable_post_data_reading = On

我的版本信息:

PHP 5.5.9-1ubuntu4.17 (cli) (built: May 19 2016 19:05:57)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

如果您仍然一无所获,请查看您的访问日志。它应该显示进入您的服务器的 POST 请求;

255.255.255.255 - - [13/Sep/2016:10:16:00 -0400] "POST /stackoverflow/welcome.php HTTP/1.1" 200 1226 "http://255.255.255.255/stackoverflow/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/255.255.255.255 Safari/537.36"

(忽略 IP 地址信息,我编辑了它以保护我的服务器 :))

如果它没有显示 POST 请求,那就是一个起点。

您也可以在浏览器上按 F12(或 ctrl+shift+i)打开调试控制台,单击网络(在顶部)在您的表单上,单击提交按钮,您将看到一个网络请求出去。单击它,单击“标题”,滚动到底部,然后查看您的浏览器实际发送到服务器的信息。

希望这批货对您有所帮助。请让我们知道:)

关于php - $_POST 在 php5.6 中为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39471257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com