我在我的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']
中,但我不知道如何获取它。
print_r($_SERVER);
输出什么? - mario