473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
2 10161
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
Many thanks Jason.

Dave.
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steven | last post by:
Hi there, I want to pass a session id from a form to a third party payment system. I have no need a of creating and maintaining sessions for the whole visit to the site. Do I just start the...
1
by: JStrummer | last post by:
I'm converting some static HTML pages to use PHP-mySQL. I will be able to add/modify/delete records via the web using phpmyadmin, but I will need to develop more user-friendly admin pages for...
6
by: SB | last post by:
This while loop keeps repeating even when a correct character is entered.... cout<<endl<<"What day would you like to schedule the appointment?"<<endl; cout<<endl<<"Enter 'M' for Monday, 'T' for...
0
by: Deano | last post by:
I have a main/subform arrangement which works well. The main form's parent records are about employees. The subform calculates their salary. I have now decided that the user can enter some...
12
by: Brett Hofer | last post by:
I must be missing something - Im a veteran C++ programmer now working with C# overall I like the language but find many weird changes... Anyway Im writing code behind an aspx. In this one C#...
1
by: chadw | last post by:
Not sure what I am missing sure its probably something very simple, I need something to get my entered text out of the textbox and entered into a database currently the code looks like this. ...
9
by: CorfuVBProgrammer | last post by:
Hello all . . . I need a help for something simple. I have create two php classes for example class classname_1 {
12
by: The Frog | last post by:
Hi all, Does anyone have a way to print forms at design time directly from the IDE? I am not a great fan of the print screen to paint to print method. I would really like to know if anyone has a...
1
bencoding
by: bencoding | last post by:
Heyo, I am new to the .NET experience and just getting my bearings. I am trying to do something simple like connect to my database and display some data through a loop. Can anyone help me with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.