Home > Backend Development > PHP Tutorial > Several solutions to php:undefined index_PHP tutorial

Several solutions to php:undefined index_PHP tutorial

WBOY
Release: 2016-07-13 17:50:55
Original
819 people have browsed it

When you usually use $_post[''], $_get[''] to get the parameters in the form, Notice: Undefined index: --------;

Although this prompt can be hidden by setting the error display mode, this also has hidden dangers, that is, these prompts will be recorded in the server's log, causing the log file to be abnormally large.

Summarized several solutions through online searches and my own actual combat;

Method 1: Modify server configuration
Modify the php.ini configuration file, error_reporting = E_ALL & ~E_NOTICE

Method 2: Initialize variables.

Method 3: Make judgment isset($_post['']), empty($_post['']) if --else

Method 4: Add @ before the notice code appears. @ indicates that there is an error in this line or a warning not to output, @$username=$_post['username'];

Method 5: The last method is very practical. It is a function written by others, and the value is transferred through this function.

Define a function:

function _get($str){
$val = !empty($_GET[$str]) ? $_GET[$str] : null;
Return $val;
}Then when using it, just use _get('str') instead of $_GET['str'] ~


Excerpted from ms.元

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478234.htmlTechArticleUsually using $_post[], $_get[] to obtain parameters in the form, Notice: Undefined index: - -------; Although you can hide this prompt by setting the error display mode, this also has hidden...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template