PHPNotice: undefinedindex perfect solution: When $ _ GET ['XX'] is used to obtain the parameter value, if you do not add a judgment before, the following warning will appear when the parameter is not passed: PHPNotice: although undefinedindexxxx can solve the problem perfectly through PHP Notice: undefined index
When you use $ _ GET ['XX'] to obtain the parameter value, if you do not add a parameter before, the following warning will appear:
PHP Notice: undefined index xxx
Although you can hide this prompt by setting the error display mode, there is also a risk that these prompts will be recorded in the server log, resulting in a huge log file exception!
The following is a reference to the popular solutions on the Internet:
First, this is not an error, it is warning. Therefore, if the server cannot be changed, each variable should be defined before use.
Method 1: modify server configurations
Modify the php. ini configuration file, error_reporting = E_ALL &~ E_NOTICE
Method 2: initialize the variables and write them in a standardized manner (complicated because there are a large number of variables ). However, we have not found a proper definition method.
Method 3: Add error_reporting (0) to the header of each file. if not, open php. ini, find display_errors, and set display_errors to Off. No errors will be prompted in the future.
Method 4: perform judgment: isset ($ _ GET ["page"]) if-else judgment
Or you can add '@' to indicate that this line is not aborted if an error occurs or a warning is reported.
For example: @ $ page = $ _ GET ["page"]
Method 5: the file1.php file pays a value for the $ xx variable and transmits it to file2.php using post,
If file2.php does not have the definition of $ xx and $ yy = $ xx is used directly, the system reports the error "undifined variaable $ xx ", if the file2.php file is defined with $ xx = "";, the $ xx value of file1.php cannot be passed!
In file2.php
If (! Isset ($ xx) $ xx = "";
However, Jones believes that these methods are not convenient. You may wish to solve the problem as follows:
Define a function:
function _get($str){ $val = !empty($_GET[$str]) ? $_GET[$str] : null; return $val;}
And then directly use it when using it?_ Get ('str ')? Just replace $ _ GET ['str ~
Is it convenient?
CodeStu