<?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>ZENVERSE &#187; session</title>
	<atom:link href="http://zenverse.net/tag/session/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenverse.net</link>
	<description>Design and Web Development</description>
	<lastBuildDate>Sun, 13 May 2012 15:26:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Session Integration for phpBB 3 in Different Folders or Subdomains</title>
		<link>http://zenverse.net/session-integration-for-phpbb-3-in-different-subdomains/</link>
		<comments>http://zenverse.net/session-integration-for-phpbb-3-in-different-subdomains/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 15:08:31 +0000</pubDate>
		<dc:creator>Zen</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://zenverse.net/?p=1126</guid>
		<description><![CDATA[A guide to integrate your phpBB 3 forum's cookie session in different folders or subdomains. Recently I looked into this matter because I need to integrate the forum's session with my premium themes area.]]></description>
			<content:encoded><![CDATA[<p>If you came from search engine, I bet you have read this guide &#8220;<a href="http://www.phpbb.com/kb/article/phpbb3-cross-site-sessions-integration/">phpBB 3 cross-site session integration</a>&#8221; at phpBB website. If you haven&#8217;t, please read if you need to understand the codes better (more descriptions at the page).</p>
<p>NOTE : if you need to integrate session for a custom file in the <u>same folder</u> as the forum, read <a href="http://www.phpbb.com/kb/article/phpbb3-sessions-integration/">this guide</a> instead.</p>
<blockquote><p>Recently I looked into this matter because I need to integrate the forum&#8217;s session with my premium themes area (which should be up in 24-48 hours).</p></blockquote>
<p>This tutorial has 2 parts:</p>
<blockquote><ul>
<li><a href="#folder">Session Integration for phpBB 3 in Different Folders</a></li>
<li><a href="#subdomain">Session Integration for phpBB 3 in Different Subdomains</a></li>
</ul>
<p><strong>You need to follow session integration for Different Folders first before going for Different Subdomains.</strong></p></blockquote>
<h3>Session Integration in <u style="color:red">Different Folders</u><a name="folder"></a></h3>
<h4>Create a custom php file</h4>
<p>Let&#8217;s look into &#8220;Different Folder&#8221; first. In my case, I created a new folder outside the forums folder. In other words, my forum directory is <em>public_html/mysite/forums</em> and my new folder is at <em>public_html/mysite/testing</em>.</p>
<p>Create a file called &#8216;index.php&#8217; inside &#8216;testing&#8217; folder and paste the following codes into the file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code1'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11261"><td class="code" id="p1126code1"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_PHPBB'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ROOT_PATH'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;../forums&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$forumurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://mysite.com/forums'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://mysite.com/testing'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_PHPBB'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ROOT_PATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$phpEx</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$phpbb_root_path</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHPBB_ROOT_PATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? PHPBB_ROOT_PATH <span style="color: #339933;">:</span> ROOT_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$phpbb_root_path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'common.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$phpEx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session_begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you want to show all your stored user data variable, use this :</p>
<blockquote><p>echo &#39;&lt;pre>&#39;; var_dump($user); echo &#39;&lt;/pre>&#39;;</p></blockquote>
<p>Edit line 4 with the path to forums folder. In my case, it is <em>../forums.<br />
Edit line 5 with the URL to the forum</em>.<br />
Edit line 6 with the URL to the new folder</em>.</p>
<h4>Identify logged-in users and guest</h4>
<p>The codes below explain it all.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11262"><td class="code" id="p1126code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> ANONYMOUS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #666666; font-style: italic;">// content for guests</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #666666; font-style: italic;">// content for members</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Login directly at your new folder</h4>
<p>This is where I stopped following the guide because the login and logout method does not work for me. I added a login form myself:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11263"><td class="code" id="p1126code3"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=login&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;username&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autologin&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #339933;">/&gt;</span> Remember Me<span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;redirect&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$newurl</span>; ?&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;login&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Login&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
Not a member? <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=register&quot;</span><span style="color: #339933;">&gt;</span>Register now<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;!</span></pre></td></tr></table></div>

<p>Note that the form has a username field and a password field, a checkbox with &#8220;remember me&#8221; option, a link to register and it redirects back to the new folder after login.</p>
<h4>Logout link</h4>
<p>Logging out would need your session id. You can get that id from <em>$user->data['session_id']</em>. This is the logout link :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11264"><td class="code" id="p1126code4"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=logout&amp;sid=&lt;?php echo <span style="color: #006699; font-weight: bold;">$user-&gt;data</span>['session_id']; ?&gt;&amp;redirect=&lt;?php echo <span style="color: #006699; font-weight: bold;">$newurl</span>; ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>Log Out<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h4>Suming up (up to here)</h4>
<p>So until here, I have this codes in my <em>public_html/mysite/testing/index.php</em>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11265"><td class="code" id="p1126code5"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_PHPBB'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ROOT_PATH'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;../forums&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$forumurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://mysite.com/forums'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://mysite.com/testing'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_PHPBB'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ROOT_PATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$phpEx</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$phpbb_root_path</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHPBB_ROOT_PATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? PHPBB_ROOT_PATH <span style="color: #339933;">:</span> ROOT_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$phpbb_root_path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'common.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$phpEx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session_begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">acl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> ANONYMOUS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #666666; font-style: italic;">// content for guests - login form</span>
<span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=login&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;username&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autologin&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #339933;">/&gt;</span> Remember Me<span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;redirect&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$newurl</span>; ?&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;login&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Login&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
Not a member? <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=register&quot;</span><span style="color: #339933;">&gt;</span>Register now<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #666666; font-style: italic;">// content for members - logout link</span>
&nbsp;
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$forumurl</span>; ?&gt;ucp.php?mode=logout&amp;sid=&lt;?php echo <span style="color: #006699; font-weight: bold;">$user-&gt;data</span>['session_id']; ?&gt;&amp;redirect=&lt;?php echo <span style="color: #006699; font-weight: bold;">$newurl</span>; ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>Log Out<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>It displays a login form for guest and a logout link for member.</p>
<h4>Redirect after login and logout</h4>
<p>Login redirect is already done if you followed my codes above. It was done using a hidden input with name &#8220;redirect&#8221;. However, logout redirect need some tweaks to work. </p>
<p>Open ucp.php from your forum&#8217;s main folder and look for:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11266"><td class="code" id="p1126code6"><pre class="php" style="font-family:monospace;">meta_refresh<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> append_sid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$phpbb_root_path}</span>index.<span style="color: #006699; font-weight: bold;">$phpEx</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Replace with :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11267"><td class="code" id="p1126code7"><pre class="php" style="font-family:monospace;">meta_refresh<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> append_sid<span style="color: #009900;">&#40;</span>request_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$phpbb_root_path}</span>index.<span style="color: #006699; font-weight: bold;">$phpEx</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Look for :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11268"><td class="code" id="p1126code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RETURN_INDEX'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> append_sid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$phpbb_root_path}</span>index.<span style="color: #006699; font-weight: bold;">$phpEx</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Replace with :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11269"><td class="code" id="p1126code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RETURN_INDEX'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> append_sid<span style="color: #009900;">&#40;</span>request_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$phpbb_root_path}</span>index.<span style="color: #006699; font-weight: bold;">$phpEx</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Explaination : The meta refresh now check for $_GET['redirect'] and use the value if it is found.</p>
<h3>Session Integration in <u style="color:red">Different Subdomains</u><a name="subdomain"></a></h3>
<p>You need to follow the guide above for the edits in ucp.php.</p>
<p>This is the guide to use same session for different subdomains. EG: your forum URL is <em>http://forums.mysite.com</em> and new subdomain is <em>http://testing.mysite.com</em></p>
<p>Based on the codes above, I changed line 5 and 6 to my new URL:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p112610"><td class="code" id="p1126code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$forumurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://forums.mysite.com/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://testing.mysite.com/'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Change Cookie domain</h4>
<p>This step is a must for different subdomains.</p>
<p>Login into admin panel > Server configuration > Cookie settings</p>
<p>Change the cookie domain to your main domain with a dot in front. In my case, my cookie domain is </p>
<blockquote><p>.mysite.com</p></blockquote>
<p>This edit makes cookie visible on all subdomains of mysite.com</p>
<h4>Redirection after login and logout don&#8217;t work!</h4>
<p>If you noticed, the redirect after login or logout does not work anymore. This is because the redirect() and meta_refresh() functions in phpBB do not allow external redirect by default. </p>
<p>Open includes/functions.php from forum&#8217;s folder :</p>
<p>Look for :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p112611"><td class="code" id="p1126code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> redirect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$disable_cd_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Replace with :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p112612"><td class="code" id="p1126code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> redirect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$disable_cd_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Look for :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p112613"><td class="code" id="p1126code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> meta_refresh<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$disable_cd_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Replace with :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1126code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p112614"><td class="code" id="p1126code14"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> meta_refresh<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$disable_cd_check</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p><strong>EXPLAINATION : Why don&#8217;t I add third argument with value of &#8220;boolean true&#8221; in the redirect() function in ucp.php?</strong><br />
I tried but it doesn&#8217;t work. Maybe it is a bug? To achieve what I want, I have to edit the third argument&#8217;s default value in functions.php.</p>
<h3>End.</h3>
<p>Hope this helps you. All comments are appreciated. If I missed something, tell me.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenverse.net/session-integration-for-phpbb-3-in-different-subdomains/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

