Php 5.4 升级到 5.6:GET 变量问题
Php 5.4 upgrade to 5.6 : GET variables issues
我使用 Mysql 数据库、PHP 会话等从头开始创建了一个小网站...在我的本地 WAMP 上使用 PHP 5.4.
将网站文件上传到我的在线主机时 - 运行 PHP 5.6 - 我的所有 GET 变量都有问题,它似乎无法正常工作。
在我的本地计算机上:
// Requested URL : index.php?title=Hello
<?php
echo $_GET["title"]; // works
?>
在服务器上:
// Requested URL : index.php?title=Hello
<?php
echo $_GET["title"]; // empty.
?>
疯了!我不明白发生了什么...我阅读了 "Migrating from PHP 5.4.x to PHP 5.6.x" 和 "Migrating from PHP 5.5.x to PHP 5.6.x",但我没能找到不起作用的地方。
你有什么想法吗?
编辑 01/13:我创建了一个非常简单的表单页面:
<?php
echo $_POST["texttest"]."<hr />";
?>
<form action="?" method="POST">
<input type="text" name="texttest" class="texttest" id="texttest" />
<input type="submit" value="test">
</form>
.. POST 变量永远不会显示。当我在提交表单后查看 Chrome 控制台时,我收到一条消息:
Provisional headers are shown
使用 phpinfo 设置测试脚本以查看主机上的 ini 变量。
<?php
phpinfo();
?>
http://php.net/manual/en/ini.core.php#ini.variables-order
如果 variables-order 以某种方式设置 - $_GET 可能不可用...
我的设置为:
; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers. You
; can still get access to the environment variables through getenv() should you
; need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"
如果您有权访问您的 php.ini - 您可以简单地更改它。
编辑:
确定 - 确认 variables_order = "GPCS".
如果源测试代码被编辑成这个-结果是什么?
<?php
echo 'This is my page'; // should always print- just to make sure you are on the correct page
echo '$_REQUEST:'.print_r($_REQUEST,true);
echo '$_GET: '.print_r($_GET,true);
echo '$_POST: '.print_r($_POST,true);
echo $_GET["title"]; // empty.
?>
; PHP 是否会读取 POST 数据。
;默认情况下启用此选项。
;您很可能不想全局禁用此选项。它导致 $_POST
; $_FILES 始终为空;您将能够阅读的唯一方法
; POST 数据将通过 php://输入流包装器。这很有用
;代理请求或以内存高效的方式处理 POST 数据。
; http://php.net/enable-post-data-reading
enable_post_data_reading = 关闭
删除;从第一行开始 ;enable_post_data_reading = Off
我使用 Mysql 数据库、PHP 会话等从头开始创建了一个小网站...在我的本地 WAMP 上使用 PHP 5.4.
将网站文件上传到我的在线主机时 - 运行 PHP 5.6 - 我的所有 GET 变量都有问题,它似乎无法正常工作。
在我的本地计算机上:
// Requested URL : index.php?title=Hello
<?php
echo $_GET["title"]; // works
?>
在服务器上:
// Requested URL : index.php?title=Hello
<?php
echo $_GET["title"]; // empty.
?>
疯了!我不明白发生了什么...我阅读了 "Migrating from PHP 5.4.x to PHP 5.6.x" 和 "Migrating from PHP 5.5.x to PHP 5.6.x",但我没能找到不起作用的地方。
你有什么想法吗?
编辑 01/13:我创建了一个非常简单的表单页面:
<?php
echo $_POST["texttest"]."<hr />";
?>
<form action="?" method="POST">
<input type="text" name="texttest" class="texttest" id="texttest" />
<input type="submit" value="test">
</form>
.. POST 变量永远不会显示。当我在提交表单后查看 Chrome 控制台时,我收到一条消息:
Provisional headers are shown
使用 phpinfo 设置测试脚本以查看主机上的 ini 变量。
<?php
phpinfo();
?>
http://php.net/manual/en/ini.core.php#ini.variables-order 如果 variables-order 以某种方式设置 - $_GET 可能不可用...
我的设置为:
; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers. You
; can still get access to the environment variables through getenv() should you
; need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"
如果您有权访问您的 php.ini - 您可以简单地更改它。
编辑:
确定 - 确认 variables_order = "GPCS".
如果源测试代码被编辑成这个-结果是什么?
<?php
echo 'This is my page'; // should always print- just to make sure you are on the correct page
echo '$_REQUEST:'.print_r($_REQUEST,true);
echo '$_GET: '.print_r($_GET,true);
echo '$_POST: '.print_r($_POST,true);
echo $_GET["title"]; // empty.
?>
; PHP 是否会读取 POST 数据。 ;默认情况下启用此选项。 ;您很可能不想全局禁用此选项。它导致 $_POST ; $_FILES 始终为空;您将能够阅读的唯一方法 ; POST 数据将通过 php://输入流包装器。这很有用 ;代理请求或以内存高效的方式处理 POST 数据。 ; http://php.net/enable-post-data-reading enable_post_data_reading = 关闭
删除;从第一行开始 ;enable_post_data_reading = Off