Page 1 of 1

SESSION Logins

Posted: Tue Oct 12, 2010 6:40 am
by vanderlooj
Hi,

I created a login system for the project that I am working on. I use a Session class that I created to log users in.

The login method of the Session class looks like this:

Code: Select all

public function login($user)
{ 
     $this->user_id = $_SESSION['user_id'] = $user->id;
     $this->logged_in = true;
}
Everything is working fine. Login. Logout no problems.

But, I created another project, using the same class (a new session class for that project) and technique to login. And that's where the problem comes in.

I have project 1 open in a tab. And I login using database 1. Then I open project 2 in another tab, which uses a different database, and then project 2 automatically redirects me to the page after login. It doesn't ask me to login in project 2. Is this because of a session value that has been set or how does this work?

Please excuse my ignorance.

Any help would be appreciated.
Thanks

Re: SESSION Logins

Posted: Tue Oct 12, 2010 10:26 am
by AbraCadaver
Sessions work by setting a cookie in the browser with the session id contained within. Cookies are identified by the domain and path. If your projects are on the same domain then PHP's default behavior is to use the same cookie because the directory is set to /. Try setting the directory in each project using session_set_cookie_params() or ini_set('session.cookie_path').