PHP $_GET and $_POST undefined problem(PHP $_GET 和 $_POST 未定义问题)
问题描述
我是 PHP 新手,如果这是一个简单的问题,我深表歉意...
I'm new to PHP so I apologize if this is a simple problem...
我正在将一个 PHP 站点从一台服务器移动到另一台服务器.新服务器是IIS 7.0,PHP 5.2.1,短标签打开开",不知道原来的服务器是怎么设置的(刚刚给了代码).
I am moving a PHP site from one server to another. The new server is IIS 7.0, PHP 5.2.1, with short open tag turned "On", and I don't know how the original server was set-up (I was just given the code).
以下是其中一个页面上的第一段代码:
The following is the very first section of code on one of the pages:
<?
ob_start();
session_start();
if($_GET['confirm'] == 13 || $_GET['confirm'] == 14 || $_GET['confirm'] == 15 || $_GET['confirm'] == 16)
{
include("test/query/test_query.php");
}
?>
这个页面执行的时候,总是显示如下错误:
When this page executes, the following error is always shown:
PHP 注意:未定义索引:在第 6 行的 [文件位置].php 中确认
PHP Notice: Undefined index: confirm in [file location].php on line 6
此外,用户通过从主页(这是一个标准的 HTML 页面)重定向来访问此页面.正确导航到的完整 URL 如下:
Also, users access this page by being redirected from the home page (which is a standard HTML page). The full URL when properly navigated to is the following:
http://www.[site].com/test.php#login>
...我明白为什么会抛出错误.我不明白的是这段代码如何像在原始服务器上那样工作.我可能缺少配置设置吗?
... I understand why the error is thrown. What I don't understand is how this code could ever work as it does on the original server. Could I be missing a configuration setting?
*同样的问题发生在整个站点的数十个位置.这只是该问题的一个特定事件.
*This same issue happens in dozens of locations all over the site. This is just one specific occurrence of the issue.
推荐答案
新服务器有 error_reporting
设置为 E_ALL.您看到的是通知,而不是错误.试试:
The new server has error_reporting
set to E_ALL. What you're seeing is a notice, not an error. Try:
error_reporting(E_ALL ^ E_NOTICE)
错误报告设置为 E_ALL 时,访问未设置的数组成员会产生错误.如果您不想降低错误报告级别,请在检查 $_GET['var'] 之前,将代码更改为:
With error reporting set to E_ALL, accessing a member of an array which is not set generates an error. If you don't wish to lower your error reporting level, before checking $_GET['var'], change your code to:
if(isset($_GET['confirm']) && ($_GET['confirm'] == 13 || $_GET['confirm'] == 14 || $_GET['confirm'] == 15 || $_GET['confirm'] == 16)) {
通过在实际访问 $_GET['confirm']
之前添加对 isset() 的调用,您将验证您没有访问未设置的数组成员.($_GET['confirm']
只会在 URL 以 ?confirm=...
或 ?something...&confirm= 结尾时设置...
)
by adding the call to isset() before you actually access $_GET['confirm']
, you will verify that you're not accessing an array member which is not set. ($_GET['confirm']
will only be set if the URL ends in ?confirm=...
or ?something...&confirm=...
)
这篇关于PHP $_GET 和 $_POST 未定义问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP $_GET 和 $_POST 未定义问题
基础教程推荐
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01