php4的session功能評述(一)
更新時(shí)間:2006年10月09日 00:00:00 作者:
php4比php3新加了session的支持。稍微用了一下,對其函數(shù)接口,內(nèi)部機(jī)制,
應(yīng)用的方便性做了大概的了解。
session的意義大家都應(yīng)該清楚,一個(gè)session可以包括數(shù)次http的請求和應(yīng)答,
比如我們用163.net,從login到logout或者超時(shí)就作為一個(gè)session,session
的唯一標(biāo)識一般是在系統(tǒng)內(nèi)部生成一個(gè)唯一的session ID,一般是一個(gè)挺長的
字符串。一個(gè)session除了session ID,還可以有自己的session data,可以
記錄和區(qū)分sesion的不同狀態(tài)。
php4對session操作提供以下接口:
session_start — Initialize session data
session_destroy — Destroys all data registered to a session
session_name — Get and/or set the current session name
session_module_name — Get and/or set the current session module
session_save_path — Get and/or set the current session save path
session_id — Get and/or set the current session id
session_register — Register a variable with the current session
session_unregister — Unregister a variable from the current session
session_is_registered — Find out if a variable is registered in a session
session_decode — Decodes session data from a string
session_encode — Encodes the current session data as a string
意義大家一看就能明白,session_start開始一個(gè)session,session_destroy結(jié)
束一個(gè)session,session_id取得當(dāng)前的session_id,session_register向當(dāng)前
的session注冊一個(gè)變量,這個(gè)很有用,比如用戶逛商場,選中了某幾樣商品你
就可以用session_register把商品名稱或者代碼register到當(dāng)前的session中。
比如下面例子(摘自php manual):
<?php
session_register("count");
$count++;
?>
Hello visitor, you have seen this page <? echo $count; ?> times.<p>
# the <?=SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
session_register可以隱式地激發(fā)session_start(如果用戶之前沒發(fā)session_
start調(diào)用),當(dāng)前的session注冊了一個(gè)變量count,每次用戶點(diǎn)擊click here
的時(shí)候,這個(gè)變量都會(huì)增一。你可以自己試一下。<?=SID?>的意義不多贅述。
應(yīng)用的方便性做了大概的了解。
session的意義大家都應(yīng)該清楚,一個(gè)session可以包括數(shù)次http的請求和應(yīng)答,
比如我們用163.net,從login到logout或者超時(shí)就作為一個(gè)session,session
的唯一標(biāo)識一般是在系統(tǒng)內(nèi)部生成一個(gè)唯一的session ID,一般是一個(gè)挺長的
字符串。一個(gè)session除了session ID,還可以有自己的session data,可以
記錄和區(qū)分sesion的不同狀態(tài)。
php4對session操作提供以下接口:
session_start — Initialize session data
session_destroy — Destroys all data registered to a session
session_name — Get and/or set the current session name
session_module_name — Get and/or set the current session module
session_save_path — Get and/or set the current session save path
session_id — Get and/or set the current session id
session_register — Register a variable with the current session
session_unregister — Unregister a variable from the current session
session_is_registered — Find out if a variable is registered in a session
session_decode — Decodes session data from a string
session_encode — Encodes the current session data as a string
意義大家一看就能明白,session_start開始一個(gè)session,session_destroy結(jié)
束一個(gè)session,session_id取得當(dāng)前的session_id,session_register向當(dāng)前
的session注冊一個(gè)變量,這個(gè)很有用,比如用戶逛商場,選中了某幾樣商品你
就可以用session_register把商品名稱或者代碼register到當(dāng)前的session中。
比如下面例子(摘自php manual):
<?php
session_register("count");
$count++;
?>
Hello visitor, you have seen this page <? echo $count; ?> times.<p>
# the <?=SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
session_register可以隱式地激發(fā)session_start(如果用戶之前沒發(fā)session_
start調(diào)用),當(dāng)前的session注冊了一個(gè)變量count,每次用戶點(diǎn)擊click here
的時(shí)候,這個(gè)變量都會(huì)增一。你可以自己試一下。<?=SID?>的意義不多贅述。
相關(guān)文章
php利用cookie實(shí)現(xiàn)訪問次數(shù)統(tǒng)計(jì)代碼
php 利用cookie實(shí)現(xiàn)訪問次數(shù)統(tǒng)計(jì),需要的朋友可以參考下。2011-05-05
如何在PHP中使用Oracle數(shù)據(jù)庫(5)
如何在PHP中使用Oracle數(shù)據(jù)庫(5)...2006-10-10
php mysql_real_escape_string函數(shù)用法與實(shí)例教程
mysql_real_escape_string() 函數(shù)用來轉(zhuǎn)義SQL語句中使用的字符串中的特殊字符2013-09-09
用PHP實(shí)現(xiàn)將GB編碼轉(zhuǎn)換為UTF8
用PHP實(shí)現(xiàn)將GB編碼轉(zhuǎn)換為UTF8...2006-11-11
php array_pop()數(shù)組函數(shù)將數(shù)組最后一個(gè)單元彈出(出棧)
函數(shù)array_pop():將數(shù)組最后一個(gè)單元彈出(出棧)2011-07-07

