<?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>Dan Hulton&#039;s blog &#187; cookies</title>
	<atom:link href="http://www.danhulton.com/blog/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danhulton.com/blog</link>
	<description>Coffee, code, contemplation.</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:31:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Sharing cookies between subdomains in Kohana PHP</title>
		<link>http://www.danhulton.com/blog/2009/01/01/sharing-cookies-between-subdomains-in-kohana-php/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sharing-cookies-between-subdomains-in-kohana-php</link>
		<comments>http://www.danhulton.com/blog/2009/01/01/sharing-cookies-between-subdomains-in-kohana-php/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 00:12:12 +0000</pubDate>
		<dc:creator>Dan Hulton</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sessions]]></category>
		<category><![CDATA[subdomains]]></category>

		<guid isPermaLink="false">http://www.danhulton.com/blog/?p=81</guid>
		<description><![CDATA[So i&#8217;m working on a little side-project again, and something cropped up that kept me occupied for about an hour. I have a subdomain for logging in, and from there, users are redirected to personalized subdomains. By default, cookies aren&#8217;t shared between subdomains, but there are various ways around that. At a basic level, the [...]]]></description>
			<content:encoded><![CDATA[<p>So i&#8217;m working on a little side-project again, and something cropped up that kept me occupied for about an hour.  I have a subdomain for logging in, and from there, users are redirected to personalized subdomains.  By default, cookies aren&#8217;t shared between subdomains, but there are various ways around that.</p>
<p>At a basic level, the domain for the cookie is typically set to &#8220;www.yourdomain.com&#8221;.  So if you have users redirected to &#8220;premium.yourdomain.com&#8221;, they lose their cookies because their domain no longer matches.  If you set the domain for your cookies to &#8220;.yourdomain.com&#8221; however, cookies set in one subdomain will match and carry over to other subdomains.</p>
<p>You can set this via php.ini, in your .htaccess files, through an ini_set() call, or even through a session_set_cookie_params() call.  However, if you&#8217;re using Kohana (as I am), what you <em>actually</em> need to do is to copy system/config/cookie.php to application/config/cookie.php and modify the domain parameter to match the following:</p>
<pre><code>$config['domain'] = substr($_SERVER['SERVER_NAME'],
                           strpos($_SERVER['SERVER_NAME'], '.'),
                           100);</code></pre>
<p>This way, no matter what server name you&#8217;re using (development or live), the right cookie domain is set.</p>
<p>One final thing to keep in mind when you&#8217;ve implemented this little solution &#8211; don&#8217;t forget to clear your cookies!  I spent a further twenty minutes thinking I&#8217;d missed something code-wise because Firefox still had a better-qualified cookie left over from before and was relying on that instead of my sparklin&#8217; new &#8220;.yourdomain.com&#8221; cookie.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danhulton.com/blog/2009/01/01/sharing-cookies-between-subdomains-in-kohana-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
