By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,572 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,572 IT Pros & Developers. It's quick & easy.

Something simple!? Sessions - admin.localhost to main.localhost

P: n/a
Hi

Why does the following code allow me to keep the same session when in
the same sub domain (ie admin.localhost), yet not when I goto another
related domain eg main.localhost?

I would like to have the same session on the related domain. I bet
the solution is really simple <grin>!...

Kind Regards

Dave.

Using IE6. Win NT, Apache 1.3.27, PHP 4.3.2.

php.ini file - shown at end of message (apologies for length).. is
actually a copy of a PHP4.3.0 ini file (problem here?)

hosts file in windows:

127.0.0.1 localhost
127.0.0.1 admin.localhost
127.0.0.1 main.localhost

httpd.conf

setup for VirtualHosts
eg
ServerName admin.localhost.com
// session_test.php -- located in admin.localhost
<?
session_start();
echo "id is " . session_id();
?>
a href="http://admin.localhost/session_test1.php" next

a href="http://main.localhost/session_test2.php" next

// session_test1.php -- located in admin.localhost
<?
session_start();
echo "id is " . session_id();
?>

// session_test2.php -- located in main.localhost
<?
session_start();
echo "id is " . session_id();
?>
php.ini relevant code:

session.save_handler = files
session.save_path = \temp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_dividend = 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 0
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_expire = 180
session.use_trans_sid = 0
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dave,

From php.net, the section on session functions, and the function
"session_set_cookie_params", it was posted by a person who just doesn't
want to receive junk mail (it was not me). Basically you have to tell
the browser that the domain is domain.com, not sub.domain.com. It's
more of a client issue than a server issue.

<begin anonymous genious stuff here>

junkmail at fluidideas dot com
22-Feb-2001 12:33
ok. hope this works. first time posting

heres a quick little snippet I came up with to pass sessions between
lots of sub domains or c names. it also contains an array walker for
reading and outputting the contents of the current array(in this case i
use it for http_session_vars)

ex:
www.fluidideas.com
chat.fluidideas.com
mypage.fluidideas.com
www.mypage.fluidideas.com
these will all have access to the session.

!!!BEGIN CUT!!!

session_set_cookie_params ( time()+9999999 , "" , ".fluidideas.com" );

if ( $HTTP_COOKIE_VARS[session_id_set] )
{ session_id( $HTTP_COOKIE_VARS[session_id_set] ); }
session_start ();
Function session_walker($Array)
{
If ( !Is_Array($Array) ) Return $Array;
Reset($Array);
While( List( $Key, $Value ) = Each( $Array ) )
{
If ( Is_Array( $Array[ $Key ] ) )
{
$Array[ $Key ] = session_walker( $Array[ $Key ] );
}
Else
{
echo "key -> " . $Key . "
\n";
echo "value -> " . $Value . "
\n";
}
}
Return $Array;
}

!!!END CUT FOR SESSION INCLUDE!!!
!!!BEGIN CUT!!!

$user_session_id = session_id();
setcookie("session_id_set","$user_session_id",time ()+9999999,"",
".fluidideas.com", "");

session_register("user");
session_register("password");
session_register("email");

!!!END CUT FOR LOGIN!!!

now this example will allow the session to carry the data from sub
domain to sub domain and it only has one flaw that i've noticed. NS 4.7
is the only browser I've seen this in (also use mozilla .8 and IE5.5)
but if the domain doesnt contain a c name the sessions wont pass.

ex: fluidideas.com not www.fluidideas.com

If someone can come up with a fix to this please email me. Thanks

</end anonymous genious posting>

Dave Mateer wrote:
Hi

Why does the following code allow me to keep the same session when in
the same sub domain (ie admin.localhost), yet not when I goto another
related domain eg main.localhost?

I would like to have the same session on the related domain. I bet
the solution is really simple <grin>!...

Kind Regards

Dave.

Using IE6. Win NT, Apache 1.3.27, PHP 4.3.2.

php.ini file - shown at end of message (apologies for length).. is
actually a copy of a PHP4.3.0 ini file (problem here?)

hosts file in windows:

127.0.0.1 localhost
127.0.0.1 admin.localhost
127.0.0.1 main.localhost

httpd.conf

setup for VirtualHosts
eg
ServerName admin.localhost.com
// session_test.php -- located in admin.localhost
<?
session_start();
echo "id is " . session_id();
?>
a href="http://admin.localhost/session_test1.php" next

a href="http://main.localhost/session_test2.php" next

// session_test1.php -- located in admin.localhost
<?
session_start();
echo "id is " . session_id();
?>

// session_test2.php -- located in main.localhost
<?
session_start();
echo "id is " . session_id();
?>
php.ini relevant code:

session.save_handler = files
session.save_path = \temp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_dividend = 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 0
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_expire = 180
session.use_trans_sid = 0


Jul 16 '05 #2

P: n/a
Many thanks Jason.

Dave.
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.