PHP POST 不起作用 [英] PHP POST not working

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

问题描述

<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>

当点击提交时,此代码应打印在文本框 name="ss" 中输入的任何内容.
但它不打印.使用 method="get" 而不是使用 post,有什么问题.

This code should print whatever is enter in text box name="ss" when click submit.
But its not printing. Working with method="get" but not with post, What's the problem.

推荐答案

如果您只是刷新页面,请执行以下操作:

If you're just refreshing the page, do:

action=''

代替:

action="<?php echo $_SERVER['PHP_SELF'];?>"

此外,将其添加到第 2 行以查看 $_POST 数组中存储的内容(如果有):

Also, add this to line 2 to see what's being stored (if anything) in the $_POST array:

var_dump( $_POST );

嗯...所以提交时它是空的?尝试将其添加到 php 文件的顶部:

Hmm... so it's empty on submit? Try adding this to the top of your php file:

if(empty($_SERVER['CONTENT_TYPE']))
{ 
  $_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded"; 
}

好的,现在检查您的 php.ini(通常需要/etc 中的 sudo 或 root):

Okay, now check your php.ini (normally requires sudo or root in /etc):

post_max_size = 8M
variables_order = "EGPCS"

你有这两个规则吗?如果是这样,请注意您分配了多少内存.任何超过 2048MB 的内容都可能会给您带来麻烦,具体取决于您的系统规格.

Do you have those two rules set? If so, be careful of how much memory you're allocating. Anything over 2048MB could start to give you trouble, depending on your system specs.

注意:如果您更改了 php.ini 文件并且 PHP 作为 apache 模块运行,则需要重新启动 apache.类似的东西:

NOTE: If you make changes to your php.ini file and PHP is running as an apache module, you'll need to restart apache. Something along the lines of:

sudo /etc/init.d/httpd restart

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

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