[PHP Learning Log] Simple Session Use

WBOY
Release: 2016-07-29 08:55:51
Original
1206 people have browsed it

<code>    首先,给出一些Session的解释:目前最实用的网络协议即HTTP超文本传输协议,它是“无状态”的,所谓“无状态”是指它在用户与服务器交互时没有存储需要交互的“状态”。而Session 是在网络应用中的“会话控制”模块。因此 Session 对象存储特定用户会话所需的信息,即之前提到的“状态”信息。这样,当用户在应用程序的 Web 页之间跳转时,存储在 Session 对象中的变量将不会丢失,而是在整个用户会话中一直存在下去,从而达到用户与服务器交互的目的。
</code>
Copy after login

Here I am learning how to use PHP Session, so I will post a piece of code first:

<code><span><span><?php</span>
    session_start();
    <span>//......code</span><span>?></span></span></code>
Copy after login

Open the session directly here, call this method, the server will identify whether there is already a session in use, if it exists It will call the session directly; if it does not exist, the server will reopen a session and assign it a unique ID.
And is the reliability of a session guaranteed? (That is, in different PHP pages, we need to open the same session) The answer is yes, the system will use the same ID session every time the "session_start()" method is called in the same session.
Then I will post another piece of code:

<code><span><span><?php</span>
    session_id(id);
    session_start();
    <span>//......code</span><span>?></span></span></code>
Copy after login

It can be seen that the difference between this code and the previous one is the addition of the call to the "session_id()" method. Here is an explanation: The "session_id()" method has two functions:

  • Open the session with the specified id.
  • Get the ID of the currently opened session.

So here we obviously open this session by specifying an opening method of id=id. The advantage of this is that the session call is more stable. (It is not recommended to do this directly. You can use cookies to store the session ID to achieve the purpose of stable reply)


References:
Session
HTTP

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the use of simple Session in [PHP Learning Log], including various aspects. 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