Original: John Coggeshall 07/31/2003
Translation: Easy
In the nearest column article ("Common Style Error (on)" and "Common Style Error (below)" I discussed some of the common makers to read and easily lead to the bad habits of BUG when writing PHP program.
In today's article, I will turn to discuss the focus of this series: when using PHP, the importance of security issues.
Focus on security issues
Far-not all
Prevent users from malignating your program is the most effective way to neglect it is to consider its possibilities when writing code. It is important to pay attention to the possible security issues in your code. Consider the following example functions designed to simplify the process of writing a large number of text files in PHP:
PHP Function Write_Text ($ FileName, $ text = ") {static $ open_files = array (); // If the file is empty, close all files IF ($ filename == null) {foreach ($ OPEN_FILES AS $ FR) ) {Fclose ($ fr);} $ index = md5 ($ filename); if (! Isset ($ OPEN_FILES [$ INDEX])) {$ Open_Files [$ 有DEX] = FOPEN ($ filename, "a "); If (! $ OPEN_FILES [$ INDEX]) Return False;} FPUTS ($ OPEN_FILES [$ INDEX], $ text); RETURN TRUE;}?> This function comes with two default parameters, file names and write Into the text. The function will check if the file has been opened; if so, the original file handle will be used. Otherwise, you will be created yourself. In both cases, the text will be written to the file. If the file name passed to the function is null, all open files will be turned off. The following is provided with an example.
If the developer is written in the format below to write multiple text files, then this function will be clear and easy to read.
Let us assume that this function exists in a separate file, this file contains code that calls this function. Next is a program, we call it quotes.php: