上一篇:php4的session功能评述(二) >>
php4的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++;
?>
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?>的意义不多赘述。
下一篇:PHP 高手之路(三) >>
相关文章:
- · 怎样在UNIX系统下安装MySQL
- · 如何在WIN2K下安装PHP4.04
- · PHP脚本数据库功能详解(下)
- · PHP脚本数据库功能详解(中)
- · PHP脚本数据库功能详解(上)
- · PHP4.04简明安装
- · 在PWS上安装PHP4.0正式版
- · 在IIS上安装PHP4.0正式版
- · PHP 和 XML: 使用expat函数(三)
- · PHP 和 XML: 使用expat函数(二)
- · PHP 和 XML: 使用expat函数(一)
- · PHP中的正规表达式(二)
- · PHP中的正规表达式(一)
- · 网络资源
- · 其他功能
- · PHP入门
- · PHP简介
- · php+mysql实现无限级分类 | 树型显示分类关系
- · PHP实现发表文章时自动保存图片
- · PHP实现在图片中添加中文文字
- · PHP中socket_read的问题
- · PHP界的大事:zend已经可以破解
- · PHP与SQL注入攻击
- · php 实现简单的权限管理
- · 有关在Windows下配置PHP+Apache+Optimizer失败的问题解决方案
- · 用PHP写的身份证验证程序
- · 用PHP写的身份证验证程序
- · LAMPJT最适用的web开发系统详细配置
- · pop mail 类 很简单的功能(自家用)
- · php 静态文件生成类(自家用)
- · http 协议下载类(自家用)
- · php 顶层类(自家用)
- · 在php中取得image按钮传递的name值
- · 用PHP或JS获取图片大小,高宽尺寸
- · PHP的目录管理函数
- · 自己写的一个UBB转换的函数
- · PHP + AJAX
- · PHP程序与服务器端通讯方法小结
