Php session logout and cleanup _ PHP Tutorial

Source: Internet
Author: User
Logout and cleanup of sessions in PHP. In PHP, the SESSION is logged out and cleared. 1. you must enable session_start () on each page before using the session in each page. 2. session_start () initializes the session. The first access will generate the logout and clearing of the SESSION in PHP.

1. you must enable session_start () on each page before using session on each page.

2. session_start () initializes the session. during the first access, a unique session ID is generated and saved on the client (saved based on cookies). during the next access, session_start () check whether there is a session ID. if there is a browser that will bring this session ID (this can be seen in ff browser by sending the header file) to determine the client.

3. the session sent to the cookie will save a session ID (session_id) on the client. you can print the cookie to see that the key value of this session_id is session_name,
Session_id () ==$ _ COOKIE [session_name ()]

4. if the cookie is disabled on the client, you must use the url to pass session_id to the SESSION of the URL.

5. when canceling a SESSION, you cannot use unset ($ _ SESSION). you can use $ _ SESSION = array () or $ _ SESSION = null. the correct method for canceling a session is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

// The correct method for canceling a session is as follows:

// 1 enable session

Session_start ();

// 2. clear the session information

$ _ SESSION = array ();

// 3. clear the sessionid of the client

If (isset ($ _ COOKIE [session_name ()])

{

SetCookie (session_name (), '', time ()-3600 ,'/');

}

// 4. completely destroy the session

Session_destroy ();

Session 1. you must enable session_start () on each page before using session on each page. 2. session_start () initializes the session. The first access will generate...

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.