search
Homephp教程php手册php Notice:Undefined index错误解决办法

Undefined index是告诉我们变量未定义或变量申明有点问题才会告诉我们一个并不致命的warning,那么我们要如何来解决这些问题呢?下面小编来给各位整理了一些解决warning问题的方法.

1.找到未定义变量进行处理,代码如下:

addslashes(htmlspecialchars(isset($_POST[$str])?$_POST[$str]:''));

2.把错误给过滤掉,代码如下:

@$page=$_GET["page"];

3.修改php.ini配置文件进行所有错误过滤,代码如下:

error_reporting = E_ALL & ~E_NOTICE 或者:

ini_set( "error_reporting", E_ALL ^ E_NOTICE );

ini_set( "display_errors", "0" );

4.在程序中直接加一个处理,代码如下:

if(!$cfg['debug']) { 
    error_reporting(0); 
    ob_start('ob_gzhandler'); 
}else { 
    error_reporting(E_ALL ^ E_NOTICE); 
}

5.在php文件最开始处加如下一句代码:error_reporting(0);

总结:上面所有方法中最好的方法是方法一,这样在对程序性能上是有很好的帮助,如果你页面错误过多直接过滤掉会影响性能的,我以前介绍过一篇这样的文章大家可在本地搜索.


永久链接:

转载随意!带上文章地址吧。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.