Home > Backend Development > PHP Tutorial > Example of using session in php_PHP tutorial

Example of using session in php_PHP tutorial

WBOY
Release: 2016-07-13 10:35:05
Original
801 people have browsed it

1. Initialization (must be used before using session, just use one for each page)

Copy code The code is as follows:

session_start();

2. Save

Copy code The code is as follows:

$_SESSION[$sessionName]=$value;

(value can be double, bool, int, array, object type data)

Example:

Copy code The code is as follows:

$_SESSION['LoginUser']="zs";

3. Take out the specified

Example:

Copy code The code is as follows:

$uName=$_SESSION['LoginUser'];

4. Delete specified

Example:

Copy code The code is as follows:

unset($_SESSION['LoginUser']);

5. Delete all sessions (delete the session file corresponding to the current browser)

Copy code The code is as follows:

session_destroy();

6. Get session_id

Copy code The code is as follows:

$session_id=session_id();
$ session_id=SID; //Constant

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/746867.htmlTechArticle1. Initialization (must be used before using session, just use one for each page) Copy the code as follows: session_start(); 2. Save the copied code as follows: $_SESSION[$session...
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