php4中session功能评述(1)

分类: php基本   出处:iocblog整理  更新时间:2009-11-04   添加到收藏  

php4比php3新加了session的支持。稍微用了一下,对其函数接口,内部机制,  
应用的方便性做了大概的了解。  
session的意义大家都应该清楚,一个session可以包括数次http的请求和应答,  
比如我们用163.net,从login到logout或者超时就作为一个session,session  
的唯一标识一般是在系统内部生成一个唯一的session id,一般是一个挺长的  
字符串。一个session除了session id,还可以有自己的session data,可以  
记录和区分sesion的不同状态。  
  
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开始一个session,session_destroy结  
束一个session,session_id取得当前的session_id,session_register向当前  
的session注册一个变量,这个很有用,比如用户逛商场,选中了某几样商品你  
就可以用session_register把商品名称或者代码register到当前的session中。  
  
比如下面例子(摘自php manual):  
  
<?php  
session_register("count");  
$count++;  
?>  [iocblog.net 来源]
  
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可以隐式地激发session_start(如果用户之前没发session_
start调用),当前的session注册了一个变量count,每次用户点击click here
的时候,这个变量都会增一。你可以自己试一下。<?=sid?>的意义不多赘述。  

[iocblog.net 来源]


Tag: Session



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。