Multiple PHP servers enable multiple sessions to run concurrently_PHP tutorial

WBOY
Release: 2016-07-21 16:04:59
Original
791 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 accustomed 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 the need to allow multiple users to enter a php application at the same time when 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 more 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); // strip out the blanks
    $micro = str_replace(".","",$micro); // strip out the periods
    $mysessionname = "po_maint" . $micro;
   }
    session_name($mysessionname); Using this name requires 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.




http://www.bkjia.com/PHPjc/315816.html

www.bkjia.com

true

TechArticleFirst 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. ASP was all the rage for a while...
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