Write portable PHP code

Source: Internet
Author: User
1. Keep configurations in a centralized manner. As a general principle, we recommend that you store most of the information in one location (possibly in a file) so that when you need to modify the information, all necessary modifications can be made at the same location. 2. Write reusable code. If you have just finished developing other websites or applications, you should be aware that you have

1. Keep configurations in a centralized manner. As a general principle, we recommend that you store most of the information in one location (possibly in a file) so that when you need to modify the information, all necessary modifications can be made at the same location. 2. Write reusable code. If you have just finished developing other websites or applications, you should be aware that you have

1. Keep configurations in a centralized manner.

As a general principle, we recommend that you store most of the information in one location (possibly in a file) so that when you need to modify the information, all necessary modifications can be made at the same location.

2. Write reusable code;

If you have just completed the development of other sites or applications, you should be aware that you already have the county seat and can easily apply the Code to new projects. The best way is to use the idea of creating reusable components or functional films to write object-oriented code.

There are many important issues to consider when balancing the possibility of code reuse:

(1) What will happen when project requirements change?

(2) Is it easy to add new functions to the code?

(3) Can I still understand the code after calling for a while?

(4) is the code easy to inherit from other applications?

(5) Can the assumptions be applied to work on other sites?

As an experienced PHP developer, you have a primary responsibility: constantly learn more profound knowledge about software development, such as design patterns and enterprise application architectures, as a way to improve development skills, more importantly, it is also a way to save time. The wider your knowledge, the lower the risk of failure when you start the next big project.

3. Always use the complete PHP tag;

PHP supports multiple styles of tags to identify code parts, including short tags ( ) And ASP style labels (<%> ). The tag style can be controlled by short_open_tag and asp_tag in php. ini. However, although you can switch these configurations, other server administrators may not make any changes, which may cause problems. When PHP and XML guard cannot be mixed together, the short tag style may cause problems.

4. Always use super global variables. Do not use register_globals;

Confirm php. the INI file contains the following code: register_globals = off; this forces you to listen to special predefined super global variables (for example, $ _ GET ['username']) to access the input data, make sure that it does not conflict with the variables created in the script.

6. Always check magic quotes.

Magic quotes is a function provided by PHP to help PHP beginners prevent security vulnerabilities on the developed site. The magic quotes function automatically adds escape characters (backslashes) to the values before the script can access the entered URL query string, post articles in the form, and cookie data ), it indicates that the string should contain quotation marks rather than the string ending quotation marks. If data is inserted directly into the database and the magic quotes function is enabled, therefore, there is no risk that malicious users may tamper with the database.

However, I prefer to close magic quotes and process the escape data of SQL statements by myself.

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.