Parsing php file

Source: Internet
Author: User

Method 1: According to the official manual, if the PHP tutorial's Safe Mode settings are too harsh, there is a scenario where the file does not exist, even if it is false.

Because the server side of the php.ini we can not manipulate, when using Ini_set () also can not close the Safe Mode mode, we have to return to the second, find a more reliable, safe detection methods to detect the existence of files. We can use $_server[' document_root ' to realize it. $_server[' Document_root ' returns the root of the Web site, and the last subdirectory of the directory does not contain the directory glyph '/', such as:
D:/www/htdocs
with the root directory, plus the path of the file that needs to be detected, we'll get an absolute path, and PHP will be able to use the file_exists () function to detect it. The above code we just need to change the first behavior (note that we added the symbol "/" before config.php):
$file =$_server[' document_root ']. " /config.php ";
as a result, the execution of the code is trustworthy and does not appear as expected.
The above methods also apply to the relevant detection functions of the directory (Is_dir ()) or file (Is_file ()), which detects whether the directory or file being secured is present.

Finally, incidentally: this type of file protected by the PHP special settings does not have to be added with the $_server[' document_root ' path when referencing (include and require) because, according to PHP documentation, they are allowed to be referenced.

Method 2: My situation is because the file is moving back and forth between Windows and Linux. The Linux file and directory access permissions are changed, resulting in files other than the owner has no access rights. Using Chmod-r 755 xxx/* solves the problem.

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.