PHP Safety (1) PHP Safety (1) Original: John Coggeshall 07/31/2003 Original: http://www.onlamp.com/pub/a/php/2003/07/31/php_foundations.html in the nearest two Column ("Common Style Error (on)" and "Common Style Error (below)") I discussed some common makers to read and easily lead to the bad habits of BUG when writing a PHP program. In today's article, I will turn to discuss the focus of this series: when using PHP, the importance of security issues. The importance of paying attention to security issues Seeing the far-off prevention of users from maliciously destroying 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 function 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 name is empty , Close all files IF ($ filename == null) {FOREACH ($ fly_files as $ fr) {fclose ($ fr);} return true;} $ index = md5 ($ filename); if (! Isset ($ Open_Files) $ index])) {$ OPEN_FILES [$ index] = 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 text to write to files. 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: