Home > Article > Backend Development > Several solutions to php:undefined index_PHP tutorial
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.元