php session的一些理解
Session储存在服务器端,根据客户端提供的SessionID来得到这个用户的文件,然后读取文件,取得变量的值,
SessionID可以使用客户端的Cookie或者Http1.1协议的Query_String(就是访问的URL的“?”后面的部分)来传送给服务器,然后服务器读取Session的目录
1. session在php.ini配置里的一些默认信息
[Session]
; Handler used to store/retrieve data.
session.save_handler = files
; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path = G:\MYOA\tmp //默认储存路径
; Whether to use cookies.
session.use_cookies = 1
;session.cookie_secure =
; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1
; Name of the session (used as cookie name).
session.name = PHPSESSID
; Initialize session on request startup.
session.auto_start = 0
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
; The path for which the cookie is valid.
session.cookie_path = /
; The domain for which the cookie is valid.
session.cookie_domain =
; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
session.cookie_httponly =
; Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php
; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.
session.gc_probability = 1
session.gc_divisor = 100
; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 36000
; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning seperately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.
session.bug_compat_42 = 0
session.bug_compat_warn = 1
; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =
; How many bytes to read from the file.
session.entropy_length = 0
; Specified here to create the session id.
session.entropy_file =
;session.entropy_length = 16
;session.entropy_file = /dev/urandom
; Set to {nocache,private,public,} to determine HTTP caching aspects.
; or leave this empty to avoid sending anti-caching headers.
session.cache_limiter = nocache
; Document expires after n minutes.
session.cache_expire = 180
; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = 0
2. session保存的默认路径在php.ini里可以查找到
session.save_path = G:\MYOA\tmp
3. 如果session有另外的储存模式的话,比如说:储存在memcache的服务器里,这里默认路径就不启作用了.
4. 如果保存时不成功,session则会丢失, 比如说:保存在memcahe里,但是php.ini里没有配置php_memcache.dll组件
5. 如果session储存在memcache服务器里,某个文件要引用session,文件头要引用保存的session路径
6. session.use_cookies:默认的值是“1”, 代表SessionID使用Cookie来传递,反之就是使用Query_String来传递;
session.name:这个就是SessionID储存的变量名称,可能是Cookie,也可能是Query_String来传递,默认值是“PHPSESSID”;
session.cookie_lifetime:这个代表SessionID在客户端Cookie储存的时间,默认是0,代表浏览器一关闭SessionID就作废……就是因为这个所以Session不能永久使用!
session.gc_maxlifetime:这个是Session数据在服务器端储存的时间,如果超过这个时间,那么Session数据就自动删除!
7. 永久保存session的方法:
a. session.gc_maxlifetime=999999999 无穷大
session.cookie_lifetime = 99999999 无穷大
session.save_path = G:\MYOA\tmp
每一个文件单一设置保存目录(php工作机制)
在超过gc_maxlifetime后,消除session
b. session_start();
ini_set('session.save_path','/tmp/');
//6个钟头
ini_set('session.gc_maxlifetime',21600);
//保存一天
$lifeTime = 24 * 3600;
setcookie(session_name(), session_id(), time() + $lifeTime, "/");
php session的一些理解相关推荐
- 12月13日 什么是help_method,session的简单理解, find_by等finder method
helper_method Declare a controller method as a helper. For example, helper_method :link_to def link_ ...
- java url重写 session_Java Web学习之Cookie和Session的深入理解
cookie机制和session机制的区别 具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. 同时我们也看到,由于才服务器端保持状态的方案 ...
- cookie 百科_Cookie和session应该这样理解
前言 虽然在学习服务器端语言的时候屡屡提到了Cookie和session这两个概念,有关Cookie和Session的接口也调用过,但始终对实现交互机制和这两者区别的理解感觉是云里雾里,于是打算静下心 ...
- Cookie 、Session、Token理解以及常见问题总结
目录 1 什么是 Cookie 和 Session 1.1 Cookie 1.2 Session 2 Cookie和Session的区别 3 Cookie 和 Session 是如何配合的 4 如何考 ...
- cookie、session、token理解
Cookie是保存在浏览器上的一些数据,一般通过HTTP响应头set cookie来设置,当然也可以通过JS脚本来直接设置,Cookie是按照网站来进行组织和保存的,每一个网站都可以在浏览器中保存一些 ...
- 我理解的session和cookie
tomcat管理session 理解tomcat是如何生成session的. 当用户请求到web资源有request.getSession()这段代码的时候,request首先会对请求的url判读是否 ...
- Session的理解
一.Session简介 Session的使用场景 当我们登陆电商网站时,无论浏览哪个页面都会显示登陆人的名字,还可以随时查看购物车里面的商品 也就是说当一个用户浏览一个网站的不同页面时,服务器怎么知道 ...
- session理解
作为一名WEB开发程序员,对session的理解是最基础的,但是现状是WEB程序员遍地都是,随便一划拉一大把,不过估计能把session能透彻理解的人应该不是很多,起码我之前对此是知之甚少,偶然看到的 ...
- Cookie和Session的区别与联系
Cookie和Session Session 会话的理解 Session的作用 HTTP协议的无状态特点 Session的实现原理(重点) Session常用方法: Cookie 基本介绍 经典案例 ...
- 什么是SESSION?(三)
本微信图文通过一个利用数据库的方式存储Session的例子,深入介绍了对Session机制的理解.本微信图文由钟锦提供.
最新文章
- [转]微软发布WF教程及大量示例
- XiaoluD的留言板
- 经典面试题:Redis 内存满了怎么办?
- method DESCRIBE failed: 401 Unauthorized
- Java:继承之super关键字,继承之私有权限,继承之方法重写,继承之object类,继承之简单工厂模式
- 【UOJ】67 新年的毒瘤 【BZOJ】1123 BLO
- centos7开启tcp6_Centos7下配置IPV6
- php注册登录遍写入 遍验证,自动注册登录验证机制的php代码
- activeperl安装不成功_SWOOLE进阶-00环境安装
- python多进程运行MIC(最大信息系数)
- mysql+文章显示_jsp+mysql文章内容分页显示
- 结合spring IOC AOP Mybatis写一个简易的银行转账案例
- 单项选择题标准化考试系统
- Windows系统设置共享文件夹及访问共享文件夹
- C语言推箱子完整代码
- linux连公共wifi怎么输密码,公共Wifi密码怎么用 公共Wifi密码使用方法
- CBinsight重磅报告 | 如何从谷歌亚马逊苹果微软脸书的9年专利之争,看5大巨头在AI行业的未来10年之争
- Visual Studio Code 基本插件
- 小程序中强制页面刷新
- 腾讯云---语音识别--一句话识别