The multi-php Server enables concurrent running of multiple sessions. Read the multi-php Server for concurrent running of multiple sessions. First, we will introduce the concept of session: session is first proposed by Microsoft and most integrated in asp. The use of sessions greatly facilitates the work of web developers. Asp became popular all over the world. Now, php4 also supports session. "> <LINK first introduces the concept of session:
The so-called session was first proposed by Microsoft and first integrated in asp. The use of sessions greatly facilitates the work of web developers. Asp became popular all over the world. Now, php4 is also added to the support of the session, showing the strength of open source again. Similar to Cookie, Session is designed to transmit data between different pages during an access period to solve the problem of stateless http protocol, but Session is simpler and safer. There is no unified translation method for Session Chinese. I am used to translating sessions. The significance of session should be clear: when you browse a website, the start and end of a web application is not closed in the browser. A session can contain http requests and responses several times. for example, we use freemail.263.net, from login to logout or timeout, as the lifetime of a session. Each created Session has a unique identifier string, called the session ID, which is sent to the client. at the same time, a unique identifier string entry is generated on the server, this identifier string can be stored in a text file or in a database. Then the program can register some Session variables under this sessionID. These variables can save text or value information as common variables, and can be read or written through Session. The unique identifier of a session is generally the unique session ID in the system, which is generally a long string.
Question:
After resolving the session concept, I wrote an invoicing system for my organization and found that multiple users need to be able to access a php application at the same time. The originally designed static and unique session ID causes Data confusion. In this way, it is imperative to dynamically generate a unique session ID.
The solution is simple: I use the php file name + timestamp as the unique session ID, so that every session in my program will be unique and will not be confused.
I will publish my source code below to help you solve the same problem.
// Start a PHP session to preserve variables.
If (empty ($ mysessionname )){
$ Micro = microtime ();
$ Micro = str_replace ("", "", $ micro); // strip out the blanks
$ Micro = str_replace (".", "", $ micro); // strip out the periods
$ Mysessionname = "po_maint". $ micro;
}
Session_name ($ mysessionname );
Session_start ();
Program notes:
I use mysessionname to pass variables for the unique sessionname between pages. if you also use this name, you must make a small change to the above program. Mysessionname cannot be the internal variable name of the session, because it already exists before the session starts. Mysessionname cannot be stored as a cookie, because multiple sessions will certainly overwrite the original cookie file. You can use an implicit form field to save it. In this way, no problem occurs. You are welcome to send a letter for discussion. Let's do better together.
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.