Home > Backend Development > PHP Tutorial > Use of PHP session_PHP tutorial

Use of PHP session_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-14 10:10:44
Original
1027 people have browsed it

1. Session can save any type of data. Because it is stored on the server (that is, it has been serialized).

2. Session operation mechanism


Session_start(); //The session has been opened, which is equivalent to reading the session information

$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();


// Works if session cookie was accepted
echo '
page 2';


page2.php
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);


Session_start declares the $_SESSION variable, assigns a value to $_SESSION -> Operates the $_SESSION variable -> writes the data in $_SESSION to the data space, and releases the variable.


To delete $_SESSION, you cannot unset it, you can make it empty: $_SESSION = array();

Delete the current $_SESSION data file session_destroy(), in the default system path C:windos/Temp. This directory can be found in your browser

Delete the cookie technology used in the browser and delete the sessionID

setCookie('PHPSESSID',time()-1);


Use the three together to completely delete the session


3. Cycles may be inconsistent.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477496.htmlTechArticle1. Session can save any type of data. Because it is stored on the server (that is, it has been serialized). 2. Session operation mechanism session_start(); //The session has been opened, which is equivalent to...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template