Page 1 of 1

sub.mysite.com session different than mysite.com/sub

Posted: Thu Jun 03, 2004 3:17 pm
by The Monkey
I'm currently programming my new, personal website again. I have a forum, and wish to have the session data from the forum inserted into my website to tie both the forum and the website together.

I put the forum in a subdomain, for I like the "professionalism" that it gives me.

However, the sessions in the subdomain.mysite.com are DIFFERENT, yes, I repeat, different, than the ones in mysite.com/subdomain. I don't know why, and I'm very frustrated.

If I'm logged into subdomain.mysite.com, then log out of mysite.com/subdomain, subdomain.mysite.com is not affected.

What should I do?

Site Session Code (lies in subdomain.mysite.com):

Code: Select all

<?PHP
$site_include_path = 'http://www.yolegoman.com/redesign/data/';
	include($site_include_path. 'config.php');
	define('IN_PHPBB', true);
$site_root_path = '/home/yolegoma/public_html/';
 $phpbb_root_path2 = '/monkeyslair/';
$phpbb_root_path = $site_root_path . $phpbb_root_path2;
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.php');

$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$loggedin = $userdata['session_logged_in'];
$username = $userdata['username'];
$usertemplate = 'adventure';
$uservisit = $userdata['user_lastvisit'];
$useremail = $userdata['user_email'];
$userwebsite = $userdata['user_website'];

	// Now we shall select the template to use
if(!$usertemplate) {
$usertemplate = 'adventure';
}
include($site_include_path. 'template/' .$usertemplate. '.php');

?>
Header.php Code (lies in mysite.com/redesign/data/):

Code: Select all

<?php
define('IN_PHPBB', true);
	include('/home/yolegoma/public_html/monkeyslair/site_session.php');

?>
Furthermore, the $usertemplate variable is NOT being passed from site_session.php to header.php.

Any help is wildly appreciated. I can not admit that there is no other work-around than to not have my forum in a subdomain...

- The Monkey

Posted: Thu Jun 03, 2004 3:28 pm
by lostboy
from the manual

use the session.cookie_domain attribute
I don't know if this is obvious or not, but since it took me forever to figure it out, i will post it...

<?
// If you want to share cookie/session info with a domain name and it's subdomains/Cnames,
// the only thing you really should have to do is:

ini_set("session.cookie_domain",".artattack.to");
session_start();

//see what we have in our session...
print_r($_SESSION);

?>

This will allow cookies/session info to be available to artattack.to as well as its Cnames (ex: http://www.artattack.to, zombie.artattack.to, squirrel.nut.artattack.to)

All this does is set the domain attribute of the set_cookie() style function sessions use since a "session" is just a cookie on your computer that php looks for that contains your session id.

I assume, therefor that you can do something of the like for cookies in javascript and such.

The silly thing about all this is that it is a "feature" of cookies to be able to span c names/subdomains. This is exactly why set_cookie() has an option domain argument. However, it seems like most of the people have had my problem have not gone in that direction or at least not posted a correct solution on the web. Google just gave me lots of hacked solutions. In my quest, i read articles about apache hacks, setting the serverside session storage folder, using file() from a sub on a file doing a print_r on the session located ont he main server, etc etc. I guess if you really know how cookies work (which i thought i did before all this mess but obviously not) then this problem seems like not much of a problem at all and a simple missunderstanding of what cookies do and why they are cool.