PHP $_POST 不起作用? [英] PHP $_POST not working?

查看:36
本文介绍了PHP $_POST 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最简单的形式,我想做的就是回显文本框中写的任何内容.

I have the simplest form possible and all I want to do is echo whatever is written in text box.

HTML:

<form action="" method="post">
  <input type="text" name="firstname">
  <input type="submit" name="submit" value="Submit">
</form>

PHP:

if(isset($_POST['submit'])){
  $test = $_POST['firstname'];
  echo $test;
}

问题是它不能在我的服务器上运行(它可以在另一台服务器上运行).有谁知道可能有什么问题?服务器上还有其他表单并且工作正常.

The problem is it's not working on my server (it works on another server). Does anyone has an idea what could be wrong? There are other forms on the server and are working fine.

推荐答案

今晚我遇到了类似的事情,这让我很生气.提交表单给我的是 $_REQUEST 中的值,而不是 $_POST 中的值.

I had something similar this evening which was driving me batty. Submitting a form was giving me the values in $_REQUEST but not in $_POST.

最终我注意到在 firebug 的网络选项卡上实际上有两个请求正在通过;首先是带有 301 响应的 POST,然后是带有 200 响应的 GET.

Eventually I noticed that there were actually two requests going through on the network tab in firebug; first a POST with a 301 response, then a GET with a 200 response.

搜索互联网,听起来大多数人认为这是因为 mod_rewrite 导致 POST 请求重定向并因此更改为 GET.

Hunting about the interwebs it sounded like most people thought this was to do with mod_rewrite causing the POST request to redirect and thus change to a GET.

在我的例子中,这不是 mod_rewrite 的错,它要简单得多……我的 POST 网址还包含一个 GET 查询字符串,该字符串在网址上没有尾部斜杠.正是这导致 apache 重定向.

In my case it wasn't mod_rewrite to blame, it was something far simpler... my URL for the POST also contained a GET query string which was starting without a trailing slash on the URL. It was this causing apache to redirect.

找出不同...

不好:http://blah.de.blah/my/path?key=value&otherkey=othervalue
好:http://blah.de.blah/my/path/?key=value&otherkey=othervalue

底部不会导致重定向并给我 $_POST!

The bottom one doesn't cause a redirect and gives me $_POST!

这篇关于PHP $_POST 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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