views:

64

answers:

4

Hello,

In a LAMP environment, if a user authenticates itself on example.com domain, hosted on server1, how can i keep him logged in on forum.example.com, hosted on server2 ?

Thank you in advance for your advise.

A: 

One option is to use a database for storing the user sessions that is accessible by both server1 and server2.

Alternatively you could explore 3rd party authentication services like OpenID

There is also the option of relying totally on stored cookies in the client's browser, but thats a bit scary.

Iraklis
i really like the idea of the crossserver database but i did a quick test and i cannot access my database from another domain. I do have access to curl would that be possible to have server2 fetch a user data from server1 via curl?
pixeline
well anything is possible, but I'm afraid you would be re-inventing the wheel. Use an SSO approach.
Iraklis
A: 

You could rely on some Single Sign-on implementation like CAS for instance.

martinsb
Ouch, that looks awfully complicated.
pixeline
It depends on what exactly you perceive as "complicated".Is learning and reading docs complicated or is it the thing that you don't want excess overhead on your servers?
martinsb
A: 

Asked and answered lots of times on Stack Overflow - the solution is to use SSO

symcbean
+1  A: 

A quick and dirty way, is to use cookies for the domain ".example.com" The preceding period will allow the cookie to be accessed by any server in that domain

php.net documentation: setcookie()

sriehl