Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall
A summary of PHP website design and deployment
This article is originally in the deployment of a clothing site encountered problems, these issues related to the PHP programming problem and PHP versions of the differences between the problems caused. Hereby made a summary, hope to be able to compare people to help, avoid unnecessary problems.
1. The first question I encountered was the session question. A careless really will let a person fall into the trap, grope for a while.
I wrote a My_session_start ($lifetime), in addition to starting a session, it also completed two functions, one is to set the survival time, that is, the function introduced lifetime variable; another is to set a session ID, we know session_ Start () has been able to automatically recover the old session ID, but if a user's cookie is deleted, the session cannot be restored, and this article is restored to the current session through the session_id saved in the membership database.
The problem is in the file that holds the public function of My_session_start ($lifetime). I have no PHP editor on the server, because the test process to modify a parameter, directly using Notepad to modify this file. After the modification of the original no problem of the program, suddenly has been an error, the value changed back still error, the picture below (another simulation of a file):
and by Outputting session_id (), you'll find session_id changing. The value of the cookie is empty. The PHPSESSID value cannot be sent to the client. We know Session_Start (); This function will read or write the cookie before starting a session, and read and recover the cookie when it is found in Phpsessid (my session_name, depending on the personal configuration), and if not, Create a new session ID and then transfer it to the cookie store. The error message of the picture is very clear, that is, session_start () before the execution, there is already output, resulting in the inability to output PHPSESSID to the cookie. But I looked carefully at the My_session_start ($lifetime) function of the file, without any empty lines, no output, what is going on. On the internet for a long while, try a lot of methods are not, the most find the reason. It turns out to be a code-screwing ghost. UTF-8 coding format has no BOM and with BOM information, and PHP is not recognized BOM header, Utf-8 BOM information is compatible with UTF-16, etc. after the version of Microsoft's own Notepad is supporting the BOM header, when I use Notepad to modify the php file, PHP file automatically added BOM header information, this header information is hidden, so the program has always been prompted to start the session can not send cookies to the client. Using Uedit to convert the file to a utf-8 (no BOM) format solves the problem. Everything is the BOM head of trouble ah.
2. Issues related to PHP version
My server PHP version is 5.2 version, I actually write the program when the use of the 5.4 version, in the final analysis is too fashionable, there is no serious study of the different versions of PHP.
The first is the __DIR__ constant, I encountered the error shown in the following figure,
My program in many places have to use this constant, to the absolute path to refer to a file, sometimes only in order to meet the requirements, I am accustomed to using this constant, but this time came across a php5.2 server, after the check __dir__ The magic constant is introduced php5.3 version, in fact, there are many other ways to replace it, such as dirname ()/$_server[document_root], and so on, there is only one change.
Second, Session_status (), php5.4 introduced, 1 on behalf of the Session_write_close () called, on behalf of the closing session write, which can sometimes improve the loading speed of the page with frames.
Summing up this issue, PHP version can not be too fashionable, try to use the mainstream version and function. Most of the time, the server is not in our control, and do not casually use Notepad to modify the PHP program.
This article originates from the Triad network: http://www.7wa7.com,A5 starts, reprint please indicate the source, thanks!