Home  >  Article  >  Backend Development  >  PHP5中Session小结(一)

PHP5中Session小结(一)

WBOY
WBOYOriginal
2016-06-13 10:39:21748browse

PHP5中Session总结(一)

一. Session的配置与应用

?

1.?bool session_start( void ); ? ? ? ? ?--?Initialize session data

2. $_SESSION[name] = value; ? ? ? ? ? ? -- Config session data

3. echo $_SESSION[name]; ? ? ? ? ? ? ? ?-- Use session

4. isset($_SESSION[name]); ? ? ? ? ? ? ?-- 判断session是否已配置

5. unset($_SESSION[name]); ? ? ? ? ? ? ?-- 删除session变量

6.?bool session_destroy( void ); ? ? ? ?-- 删除所有session

?

* session_register,session_unregister, session_is_registered在PHP5中不再使用.

? ? 简单示例:

<?php // Initialize the session.// If you are using session_name("something"), don't forget it now!session_start();// Unset all of the session variables.$_SESSION = array();// If it's desired to kill the session, also delete the session cookie.// Note: This will destroy the session, and not just the session data!if (isset($_COOKIE[session_name()])) {    setcookie(session_name(), '', time()-42000, '/');}// Finally, destroy the session.session_destroy();?>
?

?

Statement:
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