<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>程序如此灵动！ &#187; session</title>
	<atom:link href="http://newsn.net/tag/session/feed" rel="self" type="application/rss+xml" />
	<link>http://newsn.net</link>
	<description>苏南的网络日记本本  O(∩_∩)O  哈哈~</description>
	<lastBuildDate>Mon, 13 Jul 2009 02:59:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>在cakephp中用第三方程序读写session</title>
		<link>http://newsn.net/20090622/613.html</link>
		<comments>http://newsn.net/20090622/613.html#comments</comments>
		<pubDate>Mon, 22 Jun 2009 15:42:31 +0000</pubDate>
		<dc:creator>苏南</dc:creator>
				<category><![CDATA[IT.IT]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://newsn.net/20090622/613.html</guid>
		<description><![CDATA[cakephp无疑在很多方面限制都很多，无法用常规来理解其中的问题。关于session也是如此，在cakephp中，不但启用了session_id（和cookie的作用域功用很类似的东东），还设置了每10次页面请求，就从新生成新的session_id这一BT行为，让第三方程序读写cakephp的session有了非常大的障碍。感谢yoophi老师对本文的指点。

 

1、一点被忽略的php常识     php的session是默认生成一个session_id的，每次session_start都有一个新的id，一个session标示着一个session记录。而常规的程序中，一般只需要一个session_start()就行了，而cakephp中利用session_id()设置了id值，并动态改变。这使得我们在第三方程序中的session_start()之前就必须用session_id(CAKEPHP_SESSIONID)来进行加载。而这个cakephp_sessionid由于时刻在发生变化，也是无法用一个不变的常值来进行处理了。
2、cakephp中处理机制      cakephp中的session是由id区分的，而每次从新生成id后，他将这个值写入到了cookie中的cakephp值中，这就使得我们获得查看修改其中的变量成为可能。思路是，先用cookie取得id，然后在start，然后在进行修改。本文中的核心代码就2句话，懒得读文章的看这里就行了：    session_id($_COOKIE[&#34;CAKEPHP&#34;]);        session_start(); 
3、一段我写的代码
&#60;?
$task=trim($_GET[&#34;task&#34;]);
$next_flag=intval($_GET[&#34;next&#34;]);
$auth_config_file=&#34;auth.session&#34;;
$auto_vrl=&#34;/blog_front&#34;;
$login_vrl=&#34;/users/login&#34;;
switch($task){
    case &#34;init&#34;:
        do_init($next_flag);
        break;
    default:
     [...]]]></description>
		<wfw:commentRss>http://newsn.net/20090622/613.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
