<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_Janpoem</title><subtitle type="text">返璞归真</subtitle><id>http://feed.cnblogs.com/blog/u/28781/rss</id><updated>2010-06-21T15:44:39Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><generator>CNBlogs BlogServer</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/28781/rss"/><entry><id>http://www.cnblogs.com/janpoem/archive/2010/06/21/1762324.html</id><title type="text">PHP的Session托管机制容易造成漏洞</title><summary type="text">以下内容针对使用PHP的session_set_save_handler的托管机制进行PHP会话管理托管的开发人员。假定我们通过open, close, pick, dump, clear, gc六个函数对PHP的会话管理进行托管。PHP的session的gc回收机制本身没有问题，问题在于对于未进行gc回收，而又已经过时了的session。PHP应用中，会话管理都可以依赖于传统的gc机制进行回收，...</summary><published>2010-06-21T15:45:00Z</published><updated>2010-06-21T15:45:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2010/06/21/1762324.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2010/06/21/1762324.html"/><content type="html">&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;以下内容针对使用PHP的session_set_save_handler的托管机制进行PHP会话管理托管的开发人员。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;假定我们通过open, close, pick, dump, clear, gc六个函数对PHP的会话管理进行托管。PHP的session的gc回收机制本身没有问题，问题在于对于未进行gc回收，而又已经过时了的session。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;PHP应用中，会话管理都可以依赖于传统的gc机制进行回收，然而当一个项目的并发越高，而gc回收的几率越高，对于数据库（或者IO）而言是一大负荷，所以面对并发高的站点，我们都会将gc回收的基数增加（ini_set('session.gc_divisor', xxxx);），这个也不是本文要讨论的问题重点，所以具体就不讨论了。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;当尝试对会话进行托管控制，实际上一方面是为了减轻PHP会话机制本身的一些弊端（减少在$_SESSION变量中存放重要的用户信息），其次，也能帮助我们更好的掌握和管理整个系统的会话。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;一个标准的设计，会话数据本身，会为其设计一个生命周期，当超过声明周期的会话，当用户的客户端再持有该session_id而发生会话处理时，则认为该session已经无效，用户当重新登录以维持与服务端的会话连接。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding-left:5px;padding-right:5px;"&gt;&#xD;
&lt;pre&gt;&lt;div&gt;&lt;!--&lt;br /&gt;&lt;br /&gt;Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt;http://www.CodeHighlighter.com/&lt;br /&gt;&lt;br /&gt;--&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;MY_APP_SID&lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_name&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_start&lt;/span&gt;&lt;span style="color: #000000;"&gt;(); &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; =&amp;gt; 此处将立刻调用刚才托管的open和pick两个函数&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;span style="line-height: 21px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;对于一个open函数：&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding-left:5px;padding-right:5px;"&gt;&#xD;
&lt;pre&gt;&lt;div&gt;&lt;!--&lt;br /&gt;&lt;br /&gt;Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt;http://www.CodeHighlighter.com/&lt;br /&gt;&lt;br /&gt;--&gt;&lt;span style="color: #0000ff;"&gt;function&lt;/span&gt;&lt;span style="color: #000000;"&gt; open(&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sessId&lt;/span&gt;&lt;span style="color: #000000;"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #800080;"&gt;$sess&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;/*&lt;/span&gt;&lt;span style="color: #008000;"&gt; 根据$sessId获取到会话数据 &lt;/span&gt;&lt;span style="color: #008000;"&gt;*/&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sess&lt;/span&gt;&lt;span style="color: #000000;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;isValid()) { &lt;/span&gt;&lt;span style="color: #008000;"&gt;/*&lt;/span&gt;&lt;span style="color: #008000;"&gt; 检查会话是否有效 &lt;/span&gt;&lt;span style="color: #008000;"&gt;*/&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;$anyVal&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;open函数，就是读取该客户端持有的sessId，并且读取该会话的value值（$_SESSION中的值），这中间PHP会内部将$anyVal进行session_decode()返回到$_SESSION中。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;当一个会话的isValid返回false的时候，我们会需要重新生成会话id，并且通知客户端更新。PHP为我们提供了这么一个函数：session_regenerate_id()，但是何时使用这个函数，是整个问题的关键。作为服务器与客户端之间的无缝转换，关键的一步在于dump的时候，偷偷的将新生成的sessId写入记录容器（数据库，内存or I/O），然而dump函数，是作为整个PHP运行过程中的末尾部分，header已经输出，你无法重新改写header。或者简单的说，我们日常编写的PHP代码，无论篇幅大小，都是经由open -&amp;gt; dump这个过程中执行的，当会话机制运行到dump过程时，我们已经无可扭转。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;解决此问题的落实点在于最初执行session_start的时候，session最初启动的时候，即可执行session_regenerate_id，但是需要一个全局的监控（这时候js的让人十分怀念，可是php无法做到）。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding-left:5px;padding-right:5px;"&gt;&#xD;
&lt;pre&gt;&lt;div&gt;&lt;!--&lt;br /&gt;&lt;br /&gt;Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt;http://www.CodeHighlighter.com/&lt;br /&gt;&lt;br /&gt;--&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;MY_APP_SID&lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #800080;"&gt;$isRegenerateId&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_name&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_start&lt;/span&gt;&lt;span style="color: #000000;"&gt;(); &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; =&amp;gt; 此处将立刻调用刚才托管的open和pick两个函数&lt;/span&gt;&lt;span style="color: #008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (&lt;/span&gt;&lt;span style="color: #800080;"&gt;$isRegenerateId&lt;/span&gt;&lt;span style="color: #000000;"&gt;)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #008080;"&gt;session_regenerate_id&lt;/span&gt;&lt;span style="color: #000000;"&gt;();&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;而在open的函数中，则是用于通知$isRegenerateId是否变更了：&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding-left:5px;padding-right:5px;"&gt;&#xD;
&lt;pre&gt;&lt;div&gt;&lt;!--&lt;br /&gt;&lt;br /&gt;Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt;http://www.CodeHighlighter.com/&lt;br /&gt;&lt;br /&gt;--&gt;&lt;span style="color: #0000ff;"&gt;function&lt;/span&gt;&lt;span style="color: #000000;"&gt; open(&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sessId&lt;/span&gt;&lt;span style="color: #000000;"&gt;) &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #000000;"&gt;....&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sess&lt;/span&gt;&lt;span style="color: #000000;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;isValid()) { &lt;/span&gt;&lt;span style="color: #008000;"&gt;/*&lt;/span&gt;&lt;span style="color: #008000;"&gt; 检查会话是否有效 &lt;/span&gt;&lt;span style="color: #008000;"&gt;*/&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;$anyVal&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;span style="color: #000000;"&gt; {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #800080;"&gt;$isRegenerateId&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #000000;"&gt;....&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;dump如何处理，这里就不再例举了，因为当执行了regenerate以后，全局的session_id都会自动的跟随变化。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;不过美中不足的是，PHP的OOP的闭合特性不够强大，$isRegenerateId这么一个重要的变量，暴露在任何环境中都是极度危险的，即便使用private也是十分危险的，越是私有，越容易让代码的状态不可控（这方面让人非常羡慕Scala，一个能同时拥有val和var，你只需要声明sealed类作为一个全局的监视器，就能轻松解决此问题，可惜PHP不行）。于是可以有以下方式进行调整：&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding-left:5px;padding-right:5px;"&gt;&#xD;
&lt;pre&gt;&lt;div&gt;&lt;!--&lt;br /&gt;&lt;br /&gt;Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt;http://www.CodeHighlighter.com/&lt;br /&gt;&lt;br /&gt;--&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;MY_APP_SID&lt;/span&gt;&lt;span style="color: #000000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_name&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800080;"&gt;$sessName&lt;/span&gt;&lt;span style="color: #000000;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #008080;"&gt;session_start&lt;/span&gt;&lt;span style="color: #000000;"&gt;(); &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; =&amp;gt; 此处将立刻调用刚才托管的open和pick两个函数&lt;/span&gt;&lt;span style="color: #008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (&lt;/span&gt;&lt;span style="color: #008080;"&gt;defined&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #000000;"&gt;'&lt;/span&gt;&lt;span style="color: #000000;"&gt;REGENERATE_SESS_ID&lt;/span&gt;&lt;span style="color: #000000;"&gt;'&lt;/span&gt;&lt;span style="color: #000000;"&gt;))&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: #008080;"&gt;session_regenerate_id&lt;/span&gt;&lt;span style="color: #000000;"&gt;();&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;很自然的，open里面，当isValid为false时，define('REGENERATE_SESS_ID', true)即可。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;最后说说，不进行regenerate的后果是什么：&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;首先，从会话托管的设计初衷而言，让每一个会话本身具有生命周期，就是为了避开沉重的全局回收，让session数据得以冗余而暂时存在，却又不会对该会话持有者造成太大的影响与干扰，如果强行删除会话，客户端必然需要重新登录，这也只是其中的一种情况，如果没有控制好，可能会导致同样的sessId存在多条实例，或者本应超过生命周期的会话重新被激活。当然，也许处在全局的安全性考虑，客户端的个别体验都可以忽略不计，尤其是网站应用方面而言，很少有持续维持会话生命超过十几个小时的。然而这也仅限于网站方面，对于API，或者游戏，对于会话生命周期的要求，就越发的严格。如果站在企业级应用，某些时刻，某些局部，真的是分秒必争。能做到无缝的session生命周期的传承与转换，还是十分重要的。&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;&lt;br style="padding: 0px; margin: 0px;" /&gt;&lt;/p&gt;&#xD;
&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 3px; margin-left: 0px; line-height: 1.8em; padding: 0px;"&gt;其次，作为一个系统而言，session往往持有着重大的用户信息，无论怎么完善的系统设计，客户端和服务器之间总需要一条红绳。在特殊应用中，session总是会持有更多特殊的数据，安全的转移，并制造适当的冗余，才能为日后的数据管理，数据回报提供更加完善准确的数据。再者，只有全面的实现设计的全部，才能总结并推演出更加完善的结构，不知道bug的存在，才是最大的风险。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/janpoem/aggbug/1762324.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/janpoem/archive/2010/06/21/1762324.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2010/02/06/1664786.html</id><title type="text">关于PHP的Session处理的问题</title><summary type="text">问题源自于深空博客的这篇文章《由会话重定向看到的对象销毁问题》，嗯，我以为这种问题早有人处理过了，因为2年前我就解决了此问题。解决办法已经发在phpchina.com的原创区：《关于PHP的Session处理的问题》。不过我在自己的博客上也发表同样的一篇帖子，留作备份。在专家板块看到有人提出对Session处理机制的问题，原文《由会话重定向看到的对象销毁问题》。由于本人没有在专家板块发帖的资格，所...</summary><published>2010-02-05T18:35:00Z</published><updated>2010-02-05T18:35:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2010/02/06/1664786.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2010/02/06/1664786.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/12/29/1635375.html</id><title type="text">Eclipse 3.5汉化包打包下载</title><summary type="text">Eclipse 3.5汉化包，这是官方的汉化包，但是分40个包下载，而且Eclipse的汉化包下载也改了，没法用软件一次性下载了，每次都要点40＊3＝120次连接，疯了，打个包。。。。点击下载</summary><published>2009-12-29T11:55:00Z</published><updated>2009-12-29T11:55:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/12/29/1635375.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/12/29/1635375.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/12/12/1622576.html</id><title type="text">[转]Benchmarking magic</title><summary type="text">原文：http://www.garfieldtech.com/blog/magic-benchmarksThe day is nearly upon us! Drupal 7 will open up developers to PHP 5 functionality when it is released next year. Already, there is talk of how, and...</summary><published>2009-12-12T08:35:00Z</published><updated>2009-12-12T08:35:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/12/12/1622576.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/12/12/1622576.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/12/12/1622570.html</id><title type="text">[转]重新发现HTML表格</title><summary type="text">原文：http://www.qianduan.net/rediscovering-html-tables.html根 据我最近的一些实践以及在和一些读者进行关于HTML表格的使用问题沟通之后，决定写这篇文章。总的来说，我注意到由于误导性信息，他们对于 table的使用有种先入为主的厌恶。事实上很多人会说&amp;#8221;我看到永远不应该使用表格&amp;#8221;的说法，但是这绝对是错误的！这个建议只是针对...</summary><published>2009-12-12T08:32:00Z</published><updated>2009-12-12T08:32:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/12/12/1622570.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/12/12/1622570.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/12/11/1621616.html</id><title type="text">[转]在网页中嵌入任意字体的解决方案</title><summary type="text">原文作者：IIduce原文地址：http://css9.net/css-font-face-solution/ 作者博客：http://css9.net/字体使用是网页设计中不可或缺的一部分。经常地，我们希望在网页中使用某一特定字体，但是该字体并非主流操作系统的内置字体，这样用户在浏览页面的时候就有可能看不到真实的设计。美工设计师最常做的办法是把想要的文字做成图片，这样做有几个明显缺陷：1. 不可...</summary><published>2009-12-11T01:03:00Z</published><updated>2009-12-11T01:03:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/12/11/1621616.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/12/11/1621616.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/11/17/1604994.html</id><title type="text">50款优秀而又实用的PHP工具</title><summary type="text">国外著名网站smashingmagazine给大家带来了50款优秀而又实用的PHP工具，其中包括PHP代码测试、优化工具，图像处理工具，以及开发过程必须的软件配置管理工具等，相信这些工具能够让使用PHP的朋友如虎添翼！ 50款优秀而又实用的PHP工具：一、PHP代码调试工具Webgrind Webgrind完美支持PHP 5，安装迅速简便，可以跨越多个平台运行。 Xdebug Xdebug是使用极...</summary><published>2009-11-17T14:57:00Z</published><updated>2009-11-17T14:57:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/11/17/1604994.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/11/17/1604994.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/08/02/1536965.html</id><title type="text">对于Ajax弹出层的标准接口的一些设想</title><summary type="text">我做过各式各样的弹出层，简单的bg+border，或者复杂的9宫格的弹出层，我总是习惯的将这种弹出层称呼为widget。一个widget应该具备以下典型的接口：一、基础接口：所谓基础接口，是指，作为一个弹出层，所必须具备的一些基本面貌。方法，open([options]) - 显示可选参数options，object类型。未设时，使用内部继承的options，重新定制弹出层实例的设置，用于重新定制...</summary><published>2009-08-02T08:20:00Z</published><updated>2009-08-02T08:20:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/08/02/1536965.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/08/02/1536965.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/08/01/1536718.html</id><title type="text">[转]NetBeans 6.5 界面美化与字体设置</title><summary type="text">原文:http://hi.baidu.com/dosmark/blog/item/d4528a8b2cf1ead4fc1f10fb.html  安装最新的 JDK 必须安装 Java SE Development Kit (JDK) 6 Update 10 或更新的版本，早期版本对字体反锯齿支持不好。 下载地址：http://java.sun.com/javase/downloads/index....</summary><published>2009-08-01T14:53:00Z</published><updated>2009-08-01T14:53:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/08/01/1536718.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/08/01/1536718.html"/></entry><entry><id>http://www.cnblogs.com/janpoem/archive/2009/08/01/1536319.html</id><title type="text">[转帖]为 PHP 应用提速、提速、再提速！</title><summary type="text">第 1 部分: 使用操作码缓存软件提升性能和吞吐量原文：http://www.ibm.com/developerworks/cn/opensource/os-php-fastapps1/PHP 是一种脚本语言，常用于创建 Web 应用程序。它易于掌握，并能迅速生成可视化结果。然而，由于 PHP 是以解释的方式执行的，所以 PHP  代码每次执行时都会被解析和转换成操作码（opcode）。操作码缓存...</summary><published>2009-07-31T18:55:00Z</published><updated>2009-07-31T18:55:00Z</updated><author><name>Janpoem</name><uri>http://www.cnblogs.com/janpoem/</uri></author><link rel="alternate" href="http://www.cnblogs.com/janpoem/archive/2009/08/01/1536319.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/janpoem/archive/2009/08/01/1536319.html"/></entry></feed>
