POST方法不传递值,而GET方法正常工作 [英] POST method is not passing the values, while GET method works fine

查看:168
本文介绍了POST方法不传递值,而GET方法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机上使用POST方法提交表单时遇到了一些问题。我创建了一个非常简单的页面来测试GET和POST方法是否工作,但只有GET方法正在检索值。代码如下:

表单代码:

 < ; form method =postaction =login.php> 
< input type =textname =username>< br>
< input type =passwordname =password>< br>
< input type =submitvalue =Login>
< / form>

在login.php页面中,我只发出一个简单命令来测试是否有任何值$ _POST变量:

 <?php var_dump($ _ POST);?> 

结果是一个空数组。



但是,如果将方法更改为GET,则命令

 <?php var_dump($ _ GET);? > 

会显示以下结果:

  array(size = 2)
'username'=>字符串'test'(长度= 4)
'密码'=> string'test'(length = 4)

我搜索了很多线程,但大多数指出编码错误,这似乎不是这里的情况。无论如何,如果这些信息有用,我正在使用WampServer 2.5和PhpStorm 10。



非常感谢您的帮助!



Best,
Lauro

解决方案

我的猜测是,这是一个PHPStorm 10问题href =https://devnet.jetbrains.com/message/5566345 =nofollow>见这里)。他们很可能会很快修复它。



您可以使用 file_get_contents('php:// input'); ,或者恢复到早期版本的PHPStorm。



您也可以使用类似Vagrant的设置虚拟机并配置PHPStorm以使用那。看起来PHPStorm已经有与Vagrant的集成

I am having some problems with the POST method for form submission in a localhost. I created a very simple page to test if both GET and POST methods work, but only the GET method is retrieving correctly the values. The code is as follows:

The form code:

<form method="post" action="login.php">
    <input type="text" name="username"><br>
    <input type="password" name="password"><br>
    <input type="submit" value="Login">
</form>

In the login.php page, I issue just a simple command to test if there is any value in the $_POST variable:

<?php var_dump($_POST);?>

which turns out to be an empty array.

However, if I change the method to GET, the command

<?php var_dump($_GET);?>

prints the following result:

array (size=2)
  'username' => string 'test' (length=4)
  'password' => string 'test' (length=4)

I have searched a lot of threads, but most of them were pointing coding errors, which does not seem to be the case here. In any case, if this information is useful, I am using WampServer 2.5 and PhpStorm 10.

Thanks a lot for your help!

Best, Lauro

解决方案

My guess is that this a PHPStorm 10 issue (see here). They'll probably fix it soon.

You can work around it by using file_get_contents('php://input');, or by reverting back to an earlier version of PHPStorm.

You might also be able set up a virtual machine with something like Vagrant and configure PHPStorm to use that. Looks like PHPStorm has an integration with Vagrant already.

这篇关于POST方法不传递值,而GET方法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆