日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP中session特点及用途,PHP特点之会话机制2——Session及其使用

發(fā)布時間:2024/9/19 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP中session特点及用途,PHP特点之会话机制2——Session及其使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

會話機制(Session)在 PHP 中用于保存并發(fā)訪問中的一些數(shù)據(jù)。這使可以幫助創(chuàng)建更為人性化的程序,增加站點的吸引力。

一個訪問者訪問你的 web 網(wǎng)站將被分配一個唯一的 id, 就是所謂的會話 id. 這個 id 可以存儲在用戶端的一個 cookie 中,也可以通過 URL 進行傳遞.

會話支持允許你將請求中的數(shù)據(jù)保存在超全局數(shù)組$_SESSION中. 當一個訪問者訪問你的網(wǎng)站,PHP 將自動檢查(如果?session.auto_start被設置為 1)或者在你要求下檢查(明確通過?session_start()?或者隱式通過?session_register()) 當前會話 id 是否是先前發(fā)送的請求創(chuàng)建. 如果是這種情況, 那么先前保存的環(huán)境將被重建.

$_SESSION?(和所有已注冊得變量) 將被 PHP 使用內(nèi)置的序列化方法在請求完成時 進行序列化.序列化方法可以通過session.serialize_handler?這個 PHP 配置選項中來設置一個指定的方法.注冊的變量未定義將被標記為未定義.在并發(fā)訪問時,這些變量不會被會話模塊 定義除非用戶后來定義了它們.

因為會話數(shù)據(jù)是被序列化的,resource?變量不能被存儲在會話中.序列化句柄 (php?和?php_binary) 會受到 register_globals 的限制. 而且,數(shù)字索引或者字符串索引包含的特殊字符(|?和?!) 不能被使用. 使用這些字符將腳本執(zhí)行關閉時的最后出現(xiàn)錯誤.?php_serialize?沒有這樣的限制.php_serialize?從 PHP 5.5.4 以后可用.

示例一、session的簡單使用:

//注冊session

session_start();

if (!isset($_SESSION['count'])) {

$_SESSION['count'] = 0;

} else {

$_SESSION['count']++;

}

//刪除session

unset($_SESSION['count']);

?>

Session相關函數(shù):

session_cache_expire?— Return current cache expire

session_cache_limiter?— Get and/or set the current cache limiter

session_commit?— session_write_close 的別名

session_decode?— Decodes session data from a session encoded string

session_destroy?— Destroys all data registered to a session

session_encode?— 將當前會話數(shù)據(jù)編碼為一個字符串

session_get_cookie_params?— Get the session cookie parameters

session_id?— Get and/or set the current session id

session_module_name?— Get and/or set the current session module

session_name?— Get and/or set the current session name

session_regenerate_id?— Update the current session id with a newly generated one

session_register_shutdown?— Session shutdown function

session_register?— Register one or more global variables with the current session

session_save_path?— Get and/or set the current session save path

session_set_cookie_params?— Set the session cookie parameters

session_set_save_handler?— Sets user-level session storage functions

session_start?— Start new or resume existing session

session_status?— Returns the current session status

session_unregister?— Unregister a global variable from the current session

session_unset?— Free all session variables

session_write_close?— Write session data and end session

總結

以上是生活随笔為你收集整理的PHP中session特点及用途,PHP特点之会话机制2——Session及其使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。