php4的session功能评述(一)

2016-01-29 15:11 4 1 收藏

php4的session功能评述(一),php4的session功能评述(一)

【 tulaoshi.com - PHP 】

  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++;  
?  
  
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?的意义不多赘述。  

 

来源:https://www.tulaoshi.com/n/20160129/1495452.html

延伸阅读
标签: PHP
  SESSION函数库:session.inc.php3 <?php if (!isset($__session_inc__)){ $__session_inc__=1; //require("cookie.inc.php3"); # -------------------------------------------------------------------   # Session Management v1.0 21.6.1998   # (c) Wild Karl Heinz <kh.wild@wicom.at&n...
标签: Web开发
PHP4之真OO 文的作者Johan Persson是PHP中著名的JpGraph图表类库的开发者. 本文是作者对于在PHP4中进行面向对象开发时需要注意的几个小问题的总结. 翻译: Binzy Wu [Mail: Binzy at JustDN dot COM], 水平有限, 欢迎探讨. 2004-2-4 简介 本文的对象是那些曾使用更加成熟的OO [1] 语言, 如Eiffel, Java, C# [2] or C++(), 进行开发的朋友(如...
标签: PHP
  <? /*************************************** ** Title.........: PHP4 HTTP Compression Speeds up the Web ** Version.......: 1.10 ** Author........: catoc <catoc@163.net ** Filename......: gzdoc.php ** Last changed..: 25/08/2000 ** Requirments...: PHP4 = 4.0.1 ** PHP was configured with --with-zlib[=...
标签: PHP
  标 题: 使用php4加速网络传输。 <? /*************************************** ** Title.........: PHP4 HTTP Compression Speeds up the Web ** Version.......: 1.10 ** Author........: catoc <catoc@163.net ** Filename......: gzdoc.php ** Last changed..: 25/08/2000 ** Requirments...: PHP4 = 4.0.1 ** &...
标签: PHP
PHP4之COOKIE支持详解      建立商业站点或者功能比较完善的个人站点,常常需要记录访问者的信息,在PHP中提供了两种方便的手段:session和cookie功能.为了永久的保持用户信息,则cookie是最便捷的手段.在这里我将为大家详细的讲解cookie的功能及使用方法.     一: 设置cookie ...

经验教程

904

收藏

81
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部