What is the security mode in php?

Source: Internet
Author: User
The manual says: Chapter 24. security mode directories are restricted or blocked by security mode function PHP's security mode is set up to solve the shared-server Security title. In terms of structure, trying to solve this title on the PHP layer is the manual saying:
Chapter 24. security mode
Directory
Functions restricted or blocked by security mode
The PHP Security mode is set up to solve the shared-server Security title. In terms of structure, it is unfair to try to solve the title on the PHP layer, but it is unrealistic to correct the WEB server layer and the control system layer. Therefore, many people, especially ISP, are currently using the application security mode.


Table 24-1. security mode settings are as follows:

Set default options
Safe_mode Off
Safe_mode_gid 0
Safe_mode_include_dir''
Safe_mode_exec_dir 1
Open_basedir''
Safe_mode_allowed_env_vars PHP _
Safe_mode_protected_env_vars LD_LIBRARY_PATH
Disable_functions''


When safe_mode is set to on, PHP checks whether the owner of the current script matches the owner of the file held by the file function. Example:-rw-r -- 1 rasmus 33 Jul 1 19: 20 script. php
-Rw-r -- 1 root 1116 May 26/etc/passwd

Run script. php Readfile ('/etc/passwd ');
?>

If The security MODE is activated, The following error occurs: Warning: safe mode Restriction in effect. The script whose uid is 500 is not
Allowed to access/etc/passwd owned by uid 0 in/docroot/script. php on line 2



At the same time, there may be such an environment, in which the loose GID check is enough, but the strict UID check is not suitable. You can use the safe_mode_gid option to control this check. If it is set to On, the loose GID check is performed; if it is set to Off (default), the UID check is performed.

Except for safe_mode, if you have set the open_basedir option, all file control will be restricted to the directory you specified. For example:
Php_admin_value open_basedir/docroot


If you run the same script. php after the open_basedir option is set, the result will be: Warning: open_basedir restriction in effect. File is in wrong directory in
/Docroot/script. php on line 2



You can also shield some functions independently. Note that the disable_functions option cannot be applied outside the php. ini file. that is to say, you cannot block functions in different virtual hosts or directories in the httpd. conf file. For example, we will add the following content to the php. ini file: disable_functions readfile, system

Then we will get the following output: Warning: readfile () has been disabled for security reasons in
/Docroot/script. php on line 2



Functions restricted or blocked by security mode
The following list of security modes may be incomplete or inaccurate.

Table 24-2. security mode restriction functions

Function name restrictions
Dbmopen () checks whether the file/directory you want to hold has the same UID as the script being executed.
Dbase_open () will check whether the file/directory you want to hold has the same UID as the script being executed.
Filepro () checks whether the file/directory you want to hold has the same UID as the script being executed.
Filepro_rowcount () checks whether the file/directory you want to hold has the same UID as the script being executed.

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.