Summary of php website design and deployment problems
This article was originally encountered when deploying a set of clothing websites. These problems involve the problems caused by the differences between php programming and various php versions. I would like to make a summary and hope that the comparison can be helpful to avoid unnecessary problems.
1. The first problem I encountered was the session problem. If you are not careful, you will find yourself in the trap for a long time.
I wrote a my_session_start ($ lifetime). In addition to starting a session, the my_session_start ($ lifetime) also has two functions. One is to set the survival time, that is, the lifetime variable introduced by the function; the other is to set a session id. We know that session_start () can automatically restore the old session id. However, if one user deletes a cookie, the session cannot be recovered, in this article, the session_id saved in the member database is restored to the current session.
The problem lies in the file that saves the public function my_session_start ($ lifetime. My server does not have a php editor. Because a parameter needs to be modified during the test, I directly used notepad to modify this file. After the modification, there was no problem with the program, and suddenly an error was reported. The numeric value was changed back and an error was still reported, as shown in the figure below (another simulated file ):
In addition, session_id () is output, and session_id is constantly changed. The cookie value is empty. The PHPSESSID value cannot be sent to the client. We know that session_start (); before starting a session, this function will operate on the reading or writing of cookies. When it is found that the cookie contains PHPSESSID (My session_name, depending on my personal configuration ), read and restore. If not, create a session id and send it to the cookie for saving. The error message of the image is clear, that is, the output content already exists before session_start () is executed, and phpsessid cannot be output to the cookie. But I carefully checked the file where the my_session_start ($ lifetime) function is located. There are no blank lines and no output. What is the problem. I have been searching for the Internet for a long time. I have tried many methods and I have found the most reason. It turns out to be a coder. UTF-8 encoding format has no BOM and BOM information, while PHP does not recognize the BOM header, UTF-8 bom information is to be compatible with the UTF-16 and other versions, microsoft's built-in notepad supports bom headers. When I use NotePad to modify the PHP file, the PHP file automatically adds the bom header information, which is hidden, therefore, the program always prompts that the cookie cannot be sent to the client when the session is started. After you use uedit to convert the file to UTF-8 (without BOM) format, the problem is solved. It's all about BOM.
2. Problems Related to the php version
My server php version is 5.2, and I actually use 5.4 when writing a program. In the final analysis, it is too fashionable to study the differences between php versions seriously.
The first is the _ DIR _ constant, as shown in the error I encountered,
My program uses this constant in many places and references a file with an absolute path. Sometimes this is the only way to meet the requirements. I am used to using this constant, but this time I met a php5.2 server, the _ DIR _ magic constant was introduced in php5.3. In fact, there are many other ways to replace it, such as dirname ()/$ _ SERVER [DOCUMENT_ROOT, if not, it can only be retried one by one.
Secondly, session_status () is introduced in php5.4. 1 indicates that session_write_close () has been called, and session writing is disabled. This sometimes improves loading speed on pages with frameworks.
To sum up this problem, the php version should not be too fashionable, and the mainstream versions and functions should be used as much as possible. In many cases, the server is not controlled by us. In addition, do not use NotePad to modify php programs.
This article comes from Sanhe Network: http://www.7wa7.com