Hi,
I develop various sites with log in areas. I test them all on my Mac and when time is short I grab a login area from one project and use it in the next.
I've noticed that unless I log out of each site before developing / testing the next, I get the old session variables getting mixed up. i.e. $_SESSION['user'] is the same session variable name for site A and site B.
What I'd like to be able to do is make sure that sessions are only referred to for a particular site. As all my locally running sites are all at the same IP I think the sessions are getting muddled.
Any ways round this ? Will this be a problem in the real world if someone visits 2 sites that I've made, however unlikely?
Thanks,
Ed.
unique session for a given site
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
when the server is localhost, set the session to have the path of this particular project.
$_SERVER['HTTP_HOST']
session_set_cookie_params()
$_SERVER['HTTP_HOST']
session_set_cookie_params()
I've just tried this and it doesn't seem to work. I'm not sure I get it!
I've created 2 folders on localhost. The folders named differently, with the variable $path_to_session set appropriately to each folder, but with the same session variable.
Echoing the session variable outputs the same text - although it should be different, depending on which url I go to.
I've created 2 folders on localhost. The folders named differently, with the variable $path_to_session set appropriately to each folder, but with the same session variable.
Echoing the session variable outputs the same text - although it should be different, depending on which url I go to.
Code: Select all
<?php
$path_to_session = $_SERVER['HTTP_HOST']."/~uName/theSiteFolder/";
session_set_cookie_params (0, $path_to_session);
session_start();
$_SESSION['test'] = (isset($_SESSION['test'])) ? $_SESSION['test'] : 'SomeValue' ;
echo $_SESSION['test'];
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
unless your url is: http://hostname/hostname/~uName/theSiteFolder that won't work.
remove your concatenation of HTTP_HOST.
remove your concatenation of HTTP_HOST.