PHP server Multiple PHP servers enable multiple sessions to run concurrently

WBOY
Release: 2016-07-29 08:33:20
Original
1024 people have browsed it

First, let’s introduce the concept of session:
The so-called session was first proposed by Microsoft and first integrated in asp. Due to the adoption of session, the work of web developers is greatly facilitated. For a time, ASP became popular all over the world. Now php4 has also added session support, once again showing the power of open source. Similar to Cookie, Session is designed to transmit data between different pages during a visit to solve the stateless problem of the http protocol, but Session is simpler and more secure. There is no unified translation of Session in Chinese. I am used to translating it as conversation. Everyone should be clear about the meaning of session: it is actually the beginning and end of a web application without closing the browser when browsing a website. A session can include several http requests and responses. For example, when we use freemail.263.net, the period from login to logout or timeout is regarded as the lifetime of a session. Each created Session has a unique identification string, called session ID. This string is sent to the client, and the same unique identification string entry is also generated on the server side. This identification string may be placed in a text file. Or put it in a database. The program can then register some Session variables under this sessionID. These variables can store text or numerical information like ordinary variables and can be read or written through Session. The unique identifier of a session is generally a unique session ID within the system, which is usually a very long string.
Question raised:
After understanding the concept of session, I found that I needed to allow multiple users to enter a PHP application at the same time while writing a purchase, sales and inventory system for my unit. The originally designed static unique session ID caused data confusion. In this way, dynamically generating a unique session ID becomes a top priority.
 The solution is simple: I used the php file name + timestamp as the unique session ID, so that each session in my program is in its place and there is no longer confusion.
I will publish my source code below so that friends who have the same problem can find a solution.
//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
  
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 in 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 in cookie mode, because multiple sessions will definitely overwrite the original cookie file. You can save it using hidden form fields. Then there will be no problem. Welcome to write in to discuss. Let's do better together.

The above has introduced the PHP server. Multiple PHP servers can realize multi-session concurrent operation, including PHP server content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template