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

Several solutions to php:undefined index_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:50:55754browse

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...
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