ref.session.php
2015-10-28 10:33
483 查看
SESSION函数的详细介绍
a example of php session
session_abort — Discard session array changes and finish session session_cache_expire — 返回当前缓存的到期时间 session_cache_limiter — 读取/设置缓存限制器 session_commit — session_write_close 的别名 session_decode — 解码会话数据 session_destroy — 销毁一个会话中的全部数据 session_encode — 将当前会话数据编码为一个字符串 session_get_cookie_params — 获取会话 cookie 参数 session_id — 获取/设置当前会话 ID session_is_registered — 检查变量是否在会话中已经注册 session_module_name — 获取/设置会话模块名称 session_name — 读取/设置会话名称 session_regenerate_id — 使用新生成的会话 ID 更新现有会话 ID session_register_shutdown — 关闭会话 session_register — Register one or more global variables with the current session session_reset — Re-initialize session array with original values session_save_path — 读取/设置当前会话的保存路径 session_set_cookie_params — 设置会话 cookie 参数 session_set_save_handler — 设置用户自定义会话存储函数 session_start — 启动新会话或者重用现有会话 session_status — Returns the current session status session_unregister — Unregister a global variable from the current session session_unset — Free all session variables session_write_close — Write session data and end session
a example of php session
simple session test <?php /* [EDIT by danbrown AT php DOT net: The author of this note named this file tmp.php in his/her tests. If you save it as a different name, simply update the links at the bottom to reflect the change.] */ session_start(); $sessPath = ini_get('session.save_path'); $sessCookie = ini_get('session.cookie_path'); $sessName = ini_get('session.name'); $sessVar = 'foo'; echo '<br>sessPath: ' . $sessPath; echo '<br>sessCookie: ' . $sessCookie; echo '<hr>'; if( !isset( $_GET['p'] ) ){ // instantiate new session var $_SESSION[$sessVar] = 'hello world'; }else{ if( $_GET['p'] == 1 ){ // printing session value and global cookie PHPSESSID echo $sessVar . ': '; if( isset( $_SESSION[$sessVar] ) ){ echo $_SESSION[$sessVar]; }else{ echo '[not exists]'; } echo '<br>' . $sessName . ': '; if( isset( $_COOKIE[$sessName] ) ){ echo $_COOKIE[$sessName]; }else{ if( isset( $_REQUEST[$sessName] ) ){ echo $_REQUEST[$sessName]; }else{ if( isset( $_SERVER['HTTP_COOKIE'] ) ){ echo $_SERVER['HTTP_COOKIE']; }else{ echo 'problem, check your PHP settings'; } } } }else{ // destroy session by unset() function unset( $_SESSION[$sessVar] ); // check if was destroyed if( !isset( $_SESSION[$sessVar] ) ){ echo '<br>'; echo $sessName . ' was "unseted"'; }else{ echo '<br>'; echo $sessName . ' was not "unseted"'; } } } ?> <hr> <a href=tmp.php?p=1>test 1 (printing session value)</a> <br> <a href=tmp.php?p=2>test 2 (kill session)</a> /*----------------------------------------------华丽分割线----------------------*/ <?php function getSessionData ($session_name = 'PHPSESSID', $session_save_handler = 'files') { $session_data = array(); # did we get told what the old session id was? we can't continue it without that info if (array_key_exists($session_name, $_COOKIE)) { # save current session id $session_id = $_COOKIE[$session_name]; $old_session_id = session_id(); # write and close current session session_write_close(); # grab old save handler, and switch to files $old_session_save_handler = ini_get('session.save_handler'); ini_set('session.save_handler', $session_save_handler); # now we can switch the session over, capturing the old session name $old_session_name = session_name($session_name); session_id($session_id); session_start(); # get the desired session data $session_data = $_SESSION; # close this session, switch back to the original handler, then restart the old session session_write_close(); ini_set('session.save_handler', $old_session_save_handler); session_name($old_session_name); session_id($old_session_id); session_start(); } # now return the data we just retrieved return $session_data; } ?>
相关文章推荐
- 收藏下phpexcel常用的字体设置,颜色设置和单元格保护
- ThinkPHP实现支付宝接口功能
- Thinkphp学习笔记-模板赋值
- FileInputStream从文件中读取,FileOutputStream写入时会多写入内容
- Thinkphp学习笔记-模板主题
- thinkphp下载远程图片到本地
- [Windows Server 2012] 安装IIS8.5及FTP
- Error 13 error C3861: 'GetPrivateProfileString': identifier not found
- php 压缩各格式图片,处理png格式图片背景黑色问题
- thinkphp中 select() 和find() 方法的区别
- PHP实现敏感词过滤系统
- TP框架,看完,你就能做一个TP框架做的小项目
- ntpd、ntpdate的区别
- FTP主动模式和被动模式的比较
- windows 上传ftp的一个小脚本
- Laravel报错:Session store not set on request.
- Thinkphp学习笔记-controller与view绑定
- ThinkPHP学习实践(一)ThinkPHP重要概念与技术思想索引
- 日常收集整理php正则表达式(超常用)
- PHP中基于perl的正则表达式处理函数