FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Session Question





SlowWalkere
Hi all,

On my site I use session variables to store user information (to keep them logged in and what not). Nothing special.

However, I was thinking about something today and I'm not sure how it works. Let's say I have two web-sites hosted on my account, in separate folders. Will those two sites share the same session variables, or will php create a new session when a user accesses each site?

If they share sessions, it could cause problems with logging in. For example, someone goes to Site A and logs in. They then go to Site B and the session shows they are logged in, but they don't necessarily have an account there (or the user-id doesn't match up).

I tried running some little test scripts and it seems that php creates a new session in each folder, but I was wondering if anyone knew for certain.

- Walkere
sonam
I think it is possible to use same sessions for two or more sites. Maybe you must put sessions in same folder with php.ini definition.


Sonam
hexkid
SlowWalkere wrote:
Will those two sites share the same session variables, or will php create a new session when a user accesses each site?
[...]
I tried running some little test scripts and it seems that php creates a new session in each folder, but I was wondering if anyone knew for certain.


If you use cookie based session management (the standard PHP way to do it) each domain (I guess my concept domain is the same as your concept of site; I'll keep using domain) will have its own cookie and therefore its own session.
In normal PHP use each session cookie will be linked to one only domain.

If you use URL based session management it's easier to share the session data between domains.
kv
Server sessions are at subdomain level. Session in one subdomain is not valid in onother, though they are hosted on same server and is served by same webserver.
ock1991
I assume you can use different session_name's for the different sites in separate folders, i.e.

Code:
<?php
session_name('s1');
session_start();
// ...
?>


if page is in same folder
Code:
<?php
session_name('s1');
session_start();
// ...
?>


If it isnt
Code:
<?php
session_name('s2'); //Session Name changed
session_start();
// ...
?>


Perhaps thats a use for session_name other than deception?
SlowWalkere
Oh, I didn't realize you could name the sessions. I'll look into that. Thanks Ock, I think that might be the answer I was looking for.

- Walkere
Related topics
I Have a question . Is it the server support Chinese?
Question before requesting free hosting
question abt posts/mth
Kinda dumb question regarding DNS
Mark all forums read
PHP newbie session question
A question
UT2004 U like the game? Do u have any question post here.
session variables
Session variables versus page variables
Question about extra dimensions
ASP session.timeout question
PHP Session Timeout/Max Life Time
PHP.ini and PHP session maxlifetime question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.