使用lighttpd Web服务器时$_GET和$_POST变量不存在
我在 Windows 计算机上安装了 lighttpd Web 服务器,但遇到了一个问题:在 PHP 文件中没有定义 $_GET
和 $_POST
变量。
例如,我有这个简单的脚本(tmp.php
):
<?php
echo "x: '" . $_GET ['x'] . "'<br />";
?>
当我转到地址:http://localhost/tmp.php?x=123
时,
我得到这个错误消息:
Notice: Undefined index: x in /srv/www/htdocs/tmp.php on line 3 x: ''
当我将相同的文件放在公共托管上时,我得到:
x: '123'
另外 php 命令:
empty ($_GET)
返回 true。
所有 $_POST 变量也是如此。
我的 php.ini
文件中是否存在任何配置错误?
该命令:
print_r($_SERVER);
给出以下结果:
Array (
[SERVER_SOFTWARE] => lighttpd/1.4.20
[SERVER_NAME] => localhost
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_PORT] => 80
[SERVER_ADDR] => 0.0.0.0
[REQUEST_METHOD] => GET
[REDIRECT_STATUS] => 200
[QUERY_STRING] => x=123
[REQUEST_URI] => /tmp.php?x=123
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 3150
[CONTENT_LENGTH] => 0
[SCRIPT_FILENAME] => /srv/www/htdocs/tmp.php
[SCRIPT_NAME] => /srv/www/htdocs/tmp.php
[DOCUMENT_ROOT] =>
[SYSTEMROOT] => C:\WINNT
[HTTP_ACCEPT] => */*
[HTTP_ACCEPT_LANGUAGE] => en-gb
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_HOST] => localhost
[HTTP_CONNECTION] => Keep-Alive
[WINDIR] => C:\WINNT
[PHP_SELF] => /srv/www/htdocs/tmp.php
[PATH_TRANSLATED] => /srv/www/htdocs/tmp.php
[REQUEST_TIME] => 1328287189
[argv] => Array (
[0] => /srv/www/htdocs/tmp.php )
[argc] => 1
)
因此值 x=123
存在于 $_SERVER['QUERY_STRING']
和 $_SERVER['REQUEST_URI']< 中/code>,但我不知道如何获取它。
I installed lighttpd web server on my Windows computer and I have a problem: in PHP files no $_GET
and $_POST
variables are defined.
For example I have this simple script (tmp.php
):
<?php
echo "x: '" . $_GET ['x'] . "'<br />";
?>
When I go to the address: http://localhost/tmp.php?x=123
I get this error message:
Notice: Undefined index: x in /srv/www/htdocs/tmp.php on line 3 x: ''
Whilst when I put the same file on public hosting I get:
x: '123'
Also the php command:
empty ($_GET)
returns true.
The same is for all $_POST variables.
Is there any misconfiguration in my php.ini
file?
The command:
print_r($_SERVER);
gives the following result:
Array (
[SERVER_SOFTWARE] => lighttpd/1.4.20
[SERVER_NAME] => localhost
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_PORT] => 80
[SERVER_ADDR] => 0.0.0.0
[REQUEST_METHOD] => GET
[REDIRECT_STATUS] => 200
[QUERY_STRING] => x=123
[REQUEST_URI] => /tmp.php?x=123
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 3150
[CONTENT_LENGTH] => 0
[SCRIPT_FILENAME] => /srv/www/htdocs/tmp.php
[SCRIPT_NAME] => /srv/www/htdocs/tmp.php
[DOCUMENT_ROOT] =>
[SYSTEMROOT] => C:\WINNT
[HTTP_ACCEPT] => */*
[HTTP_ACCEPT_LANGUAGE] => en-gb
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_HOST] => localhost
[HTTP_CONNECTION] => Keep-Alive
[WINDIR] => C:\WINNT
[PHP_SELF] => /srv/www/htdocs/tmp.php
[PATH_TRANSLATED] => /srv/www/htdocs/tmp.php
[REQUEST_TIME] => 1328287189
[argv] => Array (
[0] => /srv/www/htdocs/tmp.php )
[argc] => 1
)
So the value x=123
exists in $_SERVER['QUERY_STRING']
and in $_SERVER['REQUEST_URI']
, but I don't know how to get it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先让我们确保没有遗漏任何内容。
试试这个
其次尝试$_POST
制作一个简单的 html 表单并尝试发布它。
我知道这些听起来很愚蠢,但请尝试一下,以便我们排除它们。
最后你使用重写规则了吗?
查看 lighttpd.conf 中是否有提及“url.rewrite”。 Lighttpd 不会像 apache 那样尝试猜测 URL,如果您使用重写,您必须明确告诉它包含查询字符串。例如(重要的部分以粗体显示 - 将它们添加到您的重写中)。
url.rewrite = (
"^/([az]+)/([az]+)(?*)(.*)" => “/index.php?controller=$1&action=$2&**$4**”
)
Firstly lets make sure we're not missing something.
Try this
Secondly try $_POST
Make a simple html form and try to post it.
I know these sound silly, but please try them so we can rule them out.
Finally are you using rewrite rules?
Take a look in lighttpd.conf for any mention of 'url.rewrite'. Lighttpd doesn't try to guess the URL like apache, you have to specifically tell it to include the query string if your using rewrites. For example (The important bits are in bold - add them to your rewrites).
url.rewrite = (
"^/([a-z]+)/([a-z]+)(?*)(.*)" => "/index.php?controller=$1&action=$2&**$4**"
)
根据文档,这可能是由 php.ini 设置
variables_order
。默认值为
EGPCS
,但如果它以某种方式更改并且不包含字母 G,则 GET 变量将被完全忽略,并且$_GET
将为空。According to the docs, this could be caused by the php.ini setting
variables_order
.The default value is
EGPCS
, but if it was changed somehow and did not contain the letter G, GET variables would be completely ignored and$_GET
would be empty.据我所知,内容长度为零,它不应该是“零”。安装 fiddler 并检查请求期间发送的标头并检查响应标头。看来应该有标题混乱..
问候
Well as far I see content length is zero, it shouldn't be "zero". Install fiddler and check for the header send during request and check for response header. It seems that there should be header messing around..
Regards