关于phplib中的其它功能以及有关session的其它函数的使用,你可以参看它带的手册,或上它的网站看在线文档。它的老家在http://phplib.netuse.de/index.php3 。php4的session实现大都从phplib学来的,它也靠cookies保存session id,用文件系统保存变量(默认情况下)。因此,它的session变量不能保存对象(事实上能保存对象内容,但没有意义,因为它是保存在磁盘上的,不是活的对象,充其量也就是对象尸体。)不过这点的限制不是太大,我们在大部分情况下都只需要保存变量就行了。当然你也可以将session保存在数据库中,下一小节中我们会讲到怎样将session保存在数据库中。在php4中由于比php3多了session支持,所以在php.ini文件中也多了session配置选项。下面我们来看看各项的作用与意义: [Session] session.save_handler = files ; handler used to store/retrieve data(用什么保存session变量,默认情况下用文件) session.save_path = c:/temp ; argument passed to save_handler(保存session变量的目录,在linux/unix下为/tmp,在win下设为你的目录) ; in the case of files, this is the ; path where data files are stored session.use_cookies = 1 ; whether to use cookies(是否使用cookies,当然,在win下别无选择) session.name = PHPSESSID ; name of the session(默认session使用的cookies名,建议不要改动) ; is used as cookie name session.auto_start = 0 ; initialize session on request startup(是否自动启用session,当为1时,在每页中就可以不必调用session_start()函数了) session.cookie_lifetime = 0 ; lifetime in seconds of cookie(设定 cookie 送到浏览器后的保存时间,单位为秒。缺省值为 0,表示直到浏览器关闭。) ; or if 0, until browser is restarted session.cookie_path = / ; the path the cookie is valid for(cookie)(cookies有效路径) session.cookie_domain = ; the domain the cookie is valid for(cookies有效域名) session.serialize_handler = php ; handler used to serialize data(定义序列化数据的标识,本功能只有 WDDX 模块或 PHP 内部使用。缺省值为 php) ; php is the standard serializer of PHP session.gc_probability = 1 ; percentual probability that the (设定每次临时文件开始处理 (gc, garbage collection) 处理概率。缺省值为 1。 ) ; 'garbage collection' process is started ; on every session initialization session.gc_maxlifetime = 1440 ; after this number of seconds, stored(设定保存session的临时文件被清除前的存活秒数) ; data will be seen as 'garbage' and ; cleaned up by the gc process session.referer_check = ; check HTTP Referer to invalidate (决定参照到客户端的Session 代码是否要删除。有时在安全或其它考虑时,会设定不删除。缺省值为 0。) ; externally stored URLs containing ids session.entropy_length = 0 ; how many bytes to read from the file(设定 session 从高熵值资源读取的位数。缺省值为 0.) session.entropy_file = ; specified here to create the session id(设定 session 代码建立时,使用外部高熵值资源或文件来建立,例如 UNIX 系统上的 /dev/random 或 /dev/urandom。 ) ; session.entropy_length = 16 ; session.entropy_file = /dev/urandom session.cache_limiter = nocache ; set to { nocache,private,public } to (设定session缓冲限制) ; determine HTTP caching aspects session.cache_expire = 180 ; document expires after n minutes(文档有效期,单位为分钟) 在windows平台下,php4.01pl2以前的版本会出现设置session.save_path 后出错的情况,这是php的一个bug,在php4.01pl2及以后已经修正了。如果你用以前的版本,你可以将session.save_path设为"./",或设为"/temp",并在你放置php脚本的当前盘根目录下建一个名为temp的目录即可(我的php脚本放在d:apachehtdocs下,则我在d:盘根目录下建一名为temp的目录)。 在php4中有关session的函数主要有以下这些: session_start: 初始化session,需要用session的每一个页面最开始处调用。 session_destroy: 结束 session,在需要结束session处调。 session_name: 存取目前 session 名称。 session_module_name: 存取目前 session 模块。 session_save_path: 存取目前 session 路径。 session_id: 存取目前 session id号。 session_register: 注册新的session变量。 session_unregister: 删除已注册session变量。 session_is_registered: 检查session变量是否注册。 session_decode: Session 数据解码。 session_encode: Session 数据加密。 通常情况下我们只需要调用三个函数即可。 即sesssion_start()、session_register()、session_is_registered()。 在需要用到session的每一页的最开始处调用session_start()函数, 一个典型的使用session的页面如下: <?session_start()?> <html> .... <body> <? $var="hello"; session_register("var");//注册$var变量,注意没有$符号 if(session_is_registered("var"))//检查变量是否注册 echo "haha,注册了!"; else echo "sorry,还没有注册!";
?> </body> </html>  
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
2/2 首页 上一页 1 2 |