The fix method of the PHP Undefined index error _php Skill

Source: Internet
Author: User
Although you can set the error display to hide the hint, but there are also hidden dangers, that is, in the log of the server will be recorded in these prompts, resulting in unusually large log files.

First of all, this is not a mistake, it is warning. So if the server cannot be changed, each variable should be defined before it is used. There are several popular solutions on the Web:

Method 1: Server configuration modification. Modify php.ini configuration file, error_reporting = E_all & ~e_notice.
Method 2: Initialization of the variable, specification writing (more cumbersome, because there are a large number of variables). But have not found a good definition method, hope everyone advice.
Method 3: Each file head plus: error_reporting (0); If not, only open php.ini, find display_errors, set to Display_errors = off. Any future errors are not prompted.
Method 4: Make a Judgment: isset ($_get["page")) If-else judgment. or add ' @ ' to indicate the line if there are errors or warnings do not output. such as: @ $page =$_get["page"]
Method 5:file1.php file $xx variable to pay a value, by post to file2.php, if file2.php without $xx definition, and directly use $yy= $xx; The system will be an error: "Undifined variaable $xx", if the file2.php file started with $xx= ""; definition, then file1.php $xx value can not be passed. File2.php can be like this: if (!isset ($xx)) $xx = "";
If you think the above method is not good, you can also use the following method:
Copy Code code as follows:

function _get ($STR) {
$val =!empty ($_get[' str '])? $_get[' str ']: null;
return $val;
}

Define a function like this, and then use the _get (' str ') instead of $_get[' str ' just to make it easier.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.