PHP $ _GET和$ _POST未定义的问题 [英] PHP $_GET and $_POST undefined problem

查看:110
本文介绍了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页面)重定向来访问此页面。正确导航到的完整网址如下所示:

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

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未定义的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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