search
HomeBackend DevelopmentPHP TutorialLearn PHP configuration files easily_PHP tutorial

Learn PHP configuration files easily_PHP tutorial

Jul 15, 2016 pm 01:27 PM
phpone timepersonallearndeveloppublishMulti-userstudyIeasyConfiguration file

After a long period of development of PHP, many users know PHP very well. Here I will express my personal understanding and discuss with you. I believe that every PHP enthusiast will be familiar with the PHP.INI file. In the previous version of PHP, PHP3.0, it was named PHP3.INI. Open it with NOTEPAD. The file is usually in the Windows directory of the operating system. Everyone has seen that there are many semicolons "" in the PHP.INI file, just like Windows systems.

These semicolons are used to represent annotations. In other words, in order to make the PHP configuration file clear and easy to understand, the developer gives a brief description of each configuration function after the semicolon. These annotation lines will be ignored during system processing. . Of course, another benefit is that when the PHP system configuration changes, we can just add or remove comments to certain lines, which is simple and convenient.

auto_prepend_file string can specify a file to automatically parse and execute before reading all php files. It can be any file such as PHP, ASP, HTML (but not image files), which is very useful in extraordinary times. For example, if you want to add an advertisement to each PHP page, and if you are developing a website and want all visitors to authenticate before reading any PHP page, you can make your verification code into a separate file, and then Just set string to the file name here. Careful readers will ask: What if I only need these functions for certain files? Use your brain. Let’s take an example of a PHP configuration file:

<ol class="dp-xml">
<li class="alt"><span><span>myprefix.php文件  </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span>
</li>
<li class="alt"><span>if (strstr(strtoupper( PHP_SELF),"/PHPTEST/"))  </span></li>
<li class="">
<span>echo "我的广告!</span><strong><font color="#006699"><span class="tag"><span class="tag-name">BR</span><span class="tag">></span></span></font></strong><span>";  </span>
</li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

In this way, just set: auto_prepend_file="myprefix .php", then all PHP files in the phptest directory will contain your advertising header! It should also be noted that this file should be placed in the path pointed to by include_path, otherwise an error may occur, which will be mentioned below.

auto_append_file string has a similar function to the above, except that it is automatically added to the end of the PHP file, and it will not work when the PHP program exits with exit(). With this feature, we can easily add a footnote to our company address! include_path string The function of this parameter is to allow functions such as include() and require() to search for files in the path defined here. Is it a bit like the SET PATH command used in the DOS era? This parameter can provide a list of paths, but the paths are separated by colons in UNIX and semicolons in NT, and the directions of the slashes are also different. PHP configuration files such as:

<ol class="dp-xml">
<li class="alt"><span><span>UNIX例:</span><span class="attribute"><font color="#ff0000">include_path</font></span><span>=.:/home/lib  </span></span></li>
<li class="">
<span>NT 例:</span><span class="attribute"><font color="#ff0000">include_path</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">".:c:homeib"</font></span><span> 其中“.”表示当前目录。  </span>
</li>
<li class="alt"><span>gpc_order string </span></li>
</ol>

GPC is the first letter of the three variables GET/POST/COOKIE. Its order reflects the priority of the system in processing the three variables. From left to right, priority Increasingly. The default setting is GPC, so that when any two or three variables with the same name are passed to the server, the system will sort them by priority and only read the variable with a higher priority. Another example is setting it to "GP" to ignore cookies and use POST instead of GET when the access methods are the same. Of course, we should try to avoid passing variables with the same name in different ways at the same time during the programming process, otherwise the readability of the program will become worse, and there may be different output results in systems with different configurations.

magic_quotes_gpc boolean This parameter can determine the special characters contained in the three variables of GET/POST/COOKIE: single quotes, double quotes, slashes, whether to add the escape character backslash (that is, in C language Commonly used "")? Because in systems such as PHP databases, characters such as single quotes usually have special meanings. In order to distinguish them from real characters, we can set magic_quotes_gpc=on, so that if there are single quotes in the variables we get from the user side, they will be added in front. escape character, and then we can use the function stripslashes(string str); as needed (this function can remove the backslash escape character "" in the string. If there are two consecutive backslashes, remove one and leave one . If there is only one backslash, just remove it. ) to remove the escape character "", we can compare:

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"><span class="tag-name">form</span><span class="tag">></span></span></font></strong><span> </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">input</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"Text"</font></span><span> </span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">""</font></span><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"a"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">input</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"Submit"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">form</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span>
</li>
<li class=""><span>echo a;  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

Let's use the text when magic_quotes_gpc=on and off. Enter single quotes or double quotes into the box, then submit to see what the difference is? SMTP string specifies the domain name or IP address of the mail sending server, so that we can send mails. Compared with Microsoft ASP, this function of PHP is much simpler and more convenient. Someone may ask, what should I do if I do not have a mail server? It's very simple, just fill in the mail server of your local ISP. In fact, the mail-sending and receiving server is just like the post office in our real life. Mail can be sent at any post office, but mail is received at a fixed post office.

<ol class="dp-xml">
<li class="alt"><span><span>mysql.default_host string  </span></span></li>
<li class=""><span>mysql.default_user string  </span></li>
<li class="alt"><span>mysql.default_password string </span></li>
</ol>

Readers who have used ODBC know that when setting up ODBC, you always need to set the database location and its default login user name and password. These parameters also mean the same, but they are used in MYSQL. That’s all. For the sake of security, we also need to make some restrictions on the user's rights in MYSQL. Don't be lazy and use "root"! If these parameters are set for convenience, then we can directly use the function mysql_connect() to connect to the database. Note that no parameters are needed here! You may be thinking, although this is very convenient, it is also very dangerous! Don't worry, these parameters are invalid in PHP's safe mode. Let's take a look at the safe mode settings.

Safe mode boolean 这可不是WINDOWS 98的安全模式啊。当PHP系统处于安全模式下时,我们就能对PHP程序的行为进行一定的控制,这时候一些数据库比如MYSQL、INFOMIX等的默认数据库主机、用户名、口令等设置无效,非法用户就不能轻易连接数据库了。而且在安全模式下safe_mode_allowed_env_vars string该项设置表示什么类型的系统环境变量可以被程序更改,若设置成safe_mode_allowed_env_vars=PHP_则表示只有 PHP_打头的系统环境变量可以被修改,例如这时假如在程序中企图使用putenv("windir=UUU");来修改环境变量,系统就会提示一个安全模式的保护错误。还有,安全模式对系统命令system()等有一定限制,如只能在指定目录运行等,这样能对系统文件有一定的保护作用。log_errors boolean 这个参数指定PHP程序出错时是否要将错误信息记录在 LOG文档中。在NT系统中假如我们同时设置error_log =syslog的话,我们就能在事件查看器的应用程序日志里看到PHP所发生过的错误信息,这对测试一个大型的系统有些帮助。
<ol class="dp-xml">
<li class="alt"><span><span class="attribute"><font color="#ff0000">error_prepend_string</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"<font>"</font></font></span><span> </span></span></li>
<li class="">
<span></span><span class="attribute"><font color="#ff0000">error_append_string</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"</font>"</span><span> </span>
</li>
</ol>

这两个设置参数更有意思啦,按如上设置,那么我们一眼就能看到:我们的程序是否出错了!因为他的功能是把出错信息设置成显眼的红颜色了。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446490.htmlTechArticlePHP经过长时间的发展,很多用户都很了解PHP了,这里我发表一下个人理解,和大家讨论讨论。PHP.INI文件相信每位PHP爱好者都不会生疏,在...
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
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Apr 17, 2025 am 12:22 AM

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment