Home > php教程 > php手册 > body text

PHP之session的使用

WBOY
Release: 2016-06-13 10:56:24
Original
1085 people have browsed it

1. session可以保存任意类型的数据。因为是保存在服务器上的(即已经序列化)。

 

 

 

2. session运行机制


   session_start();  //已经开启了session,相当于已经读取了session信息

$_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声明$_SESSION变量,为 $_SESSION 赋值->  操作 $_SESSION变量->将 $_SESSION内的数据写入数据空间,并释放变量。

 


删除$_SESSION不能unset ,可以将其置为空: $_SESSION = array();

删除当前 $_SESSION的数据文件 session_destory(),在默认系统路径下C:windos /Temp下。 可以在浏览器中找到该目录

删除浏览器内利用cookie技术,删除sessionID

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

 


三个一起使用,即可完全删除session

 

 

 

 


3.  周期可能出现不一致的情况。


 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!