2007年06月2日

TWPUG問答 - 如何清除SESSION資料

Tags: php session reference

原問題見: SESSION怎麼釋放不掉。在 PHP 中使用 Session 前,請務必閱讀: PHP Manual::Session Handling Functions

1. Session and global variable

PHP Manual::session_register: If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().

$_SESSION 已經是一個 superglobal variable (全系統域變數),使用 $_SESSION['yourKey'] 的寫法就可以了。


2. Use reference with session data

$_SESSION 打起來太長,用參照也成,效果一樣。例:

但不能用 $_SESSION 儲存參照。You can't use references in session variables as there is no feasible way to restore a reference to another variable. 下例是錯誤示範:

3. Clean session data

要清除一個 SESSION 狀態,直接 unset() 指定項目即可。若要清部全部資料,調用 session_destroy()。例:


Posted by shirock at 樂多Roodo! │13:55 │回應(1)引用(0)PHP
樂多分類:網路/3C 共同主題:PHP基本語法 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/3387201
回應文章
謝謝大大~
讓我對SESSION的釋放有更深一層的了解了~
謝謝!!
Posted by she96965 at 2007年06月5日 10:24