When using $_GET["xx"] to obtain data, if no judgment is made before, if $_GET["xx"] does not exist, a warning like this will appear: PHP Notice: undefined index xxx.
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.
First of all, this is not an error, it is a warning. So if the server cannot be changed, each variable should be defined before use. Popular solutions online include the following:
- Method 1: Server configuration modification. Modify the php.ini configuration file, error_reporting = E_ALL & ~E_NOTICE.
- Method 2: Initialize the variables and write them in a standardized way (it is more cumbersome because there are a large number of variables). But I haven't found a good definition method yet, I hope you can give me some advice.
- Method 3: Add: error_reporting(0) to the header of each file; If that doesn’t work, just open php.ini, find display_errors, and set display_errors = Off. Any future errors will not be prompted.
- Method 4: Make judgment: isset($_GET["page"]) if-else judgment. Or add '@' to indicate that this line should not be output if there is an error or warning. For example: @$page=$_GET["page"]
- Method 5: The file1.php file assigns a value to the $xx variable and passes it to file2.php using post. If file2.php does not have the definition of $xx and uses $yy=$xx directly; the system will report an error: "undifined variaable $xx", if the file file2.php starts to be defined with $xx="";, then the $xx value of file1.php cannot be passed. This can be done in file2.php: if(!isset($xx)) $xx="";
If you feel that the above method is not easy to use, you can also use the following method:
function _get($str){
$val = !empty($_GET['str']) ? $_GET['str'] : null;
return $val;
}
Define such a function, and then when using it, just use _get('str') instead of $_GET['str'] ~ This will be more convenient.
http://www.bkjia.com/PHPjc/752546.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752546.htmlTechArticleWhen using $_GET["xx"] to obtain data, if no judgment is made before, $_GET[ "xx"] does not exist, a warning like this will appear: PHP Notice: undefined index xxx. Although it can be set incorrectly...
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