$ _POST始终为空/ PHP Storm和Xampp

时间:2017-05-30 15:19:25

标签: php post

我在phpstorm上编码,我安装了Xampp,我在php风暴中使用php.exe等配置了Xampp。

为了使其在内置服务器中工作。一切正常,但从昨天开始我就无法使用$_POST

以下是我在一个页面中的测试代码(test.php中的页面,如果我删除表单中的“action”字段,那就是同样的问题):

<?php
    var_dump($_POST);
    var_dump($_GET);

    ?>
<form method="post" action="test.php">
    <input name="test" type="text">
    <button type="submit" name="envoi">Envoyer</button>
    </form>

它告诉我

array(0) { } array(0) { }

如果我写了一些内容然后提交,我会得到相同的结果。

2 个答案:

答案 0 :(得分:1)

当页面首次加载时,POST数组为空,因此你得到

  

array(0) { } array(0) { }

这不是一个错误,它的正确结果是因为页面首次加载数组是空的,你需要的是检查表单是否已提交然后返回POST数据。

<?php

if(isset($_POST['envoi'])){

    var_dump($_POST);
}


    ?>
<form method="post" action="test.php">
    <input name="test" type="text">
    <button type="submit" name="envoi">Envoyer</button>
    </form>

在运行时这应该给你:

array(2) { ["test"]=> string(41) "what ever you have typed in the input box" ["envoi"]=> string(0) "" }

答案 1 :(得分:0)

我对谷歌进行了一些研究,早在2016年,PHPStorm自带的内置简单Web服务器似乎在处理POST请求时遇到了问题。今天可能仍然如此(不完全确定)。我建议你使用NGINX,APACHE或其他任何网络服务器。看起来你已经安装了Apache,因为你安装了XAMPP。在您的浏览器上尝试此操作:http://localhost/。如果Apache欢迎页面出现,您可以进行设置。现在尝试通过查看Apache配置设置来查找DocumentRoot。一旦找到,请确保将您的网络文件放在那里。

希望有所帮助

相关问题