Home  >  Article  >  Backend Development  >  Several solutions to php:undefined index undefined identifier undefeated js determines undefined

Several solutions to php:undefined index undefined identifier undefeated js determines undefined

WBOY
WBOYOriginal
2016-07-29 08:54:283011browse

Usually when using $_post[''], $_get[''] to get the parameters in the form, Notice: Undefined index: --------;

undefine,undefined是什么意思,js undefined,undefined undefined,undefined symbol,最长的英文单词,undefined identifier,undefeated,js判断undefined

Although You can hide this prompt by setting the error display mode, but 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 the server configuration
Modify the php.ini configuration file, error_reporting = E_ALL & ~E_NOTICE

Method 2: Initialize the 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 warn not to output, @$username=$_post['username'];

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

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']~

The above introduces several solutions to php:undefined index, including undefined content. I hope it will be helpful to friends who are interested in PHP tutorials.

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