You don't know 10 things about PHP.

Source: Internet
Author: User
Tags ini pear sql injection web database

1. Use the Ip2long () and LONG2IP () functions to convert the IP address into an integral type stored in the database. This approach minimizes storage space to nearly One-fourth (4 bytes of 15 bytes of char (15)), calculating whether a particular address is simpler in one section, and speeding up search and sorting (though sometimes just a little faster).

2. Use the CHECKDNSRR () function to verify that the domain name exists when verifying the email address. This built-in function confirms that the specified domain name resolves to an IP address. The user comments section of the PHP document for this function has a simple user-defined function that is based on CHECKDNSRR () to verify the legality of the email address. For those who think their email address is "joeuser@wwwphp.net" rather than "joeuser@php.net", this approach can easily catch them.

3. If you are using PHP 5 and MySQL 4.1 or higher, consider discarding the mysql_* series functions instead of the improved version of the Mysqli_* series functions. A good feature is that you can use preprocessing statements, and if you are maintaining a database-intensive site, this feature can speed up the query. Some assessment scores.

4. Learn to love ternary operators.

5. If you feel a reusable part of the project, see if it already exists in PEAR before you write down a line of code. Many PHP programmers know that PEAR is a good repository, although many programmers do not know it. This online repository contains more than 400 reusable pieces of program that you can use immediately with a knife in your program. Unless your project is really special, you can always find a PEAR bag that helps you save time. (See PECL)

6. Highlight_file () from the dynamic print out of the formatted very beautiful source code. This function is handy if you're looking for a script help on the message board, IRC, and other places. Of course, be careful not to accidentally leak out your database connection information and password and so on.

7. Use the error_reporting (0) function to prevent users from seeing potentially sensitive error messages. Ideally, the publisher should be completely banned in php.ini. But if you're using a shared Web server and you don't have your own php.ini file, your best bet is to add error_reporting (0) to the first line of all the scripts (or use the require_once () method). This makes it possible to completely block sensitive SQL query statements and path names when errors occur.

8. Use Gzcompress () and gzuncompress () to explicitly compress/extract strings before storing large strings in the Web database. This PHP built-in function uses the GZIP algorithm to compress ordinary text up to 90%. I use these functions every time I want to read and write to a BLOB type field. The only exception is when I need full text search.

9. Multiple return values are obtained from a function by means of passing parameters by reference. Like ternary operators, most programmers trained in formal programming know this technique. But those with HTML backgrounds greater than Pascal's background have more or less the question of returning multiple values from a function only once return is used? "The answer is to precede the variable with a" & "symbol passed by reference instead of" value. "

10. Fully understand the dangers of "magic quotes" and SQL injection. I hope that the developers who read here are already injecting and understanding SQL. But I still put this one here because it's really hard to understand. If you haven't heard of this, spend the rest of the day with Google and read it.

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.