I’m running Ubuntu / nginx and php-fpm. When I open my website http://www.mydomain.com I have to log in and a session is being created by PHP. When I log on to http://mydomain.com I have to log in again and another session is being created.
How can I prevent PHP from creating new sessions and stick with one? Or is this rather a web server issue?
This is because your sessions are based on cookies, and cookies are domain specific.
www.domain.comis technically a subdomain ofdomain.com, although it is rarely treated as such, and the browser will act as if it were a completely different server. You can work around the problem by passing the session id as a GET (or POST) parameter as appropriate.See this page or the PHP manual for an explanation of how to do it. All you really need to do is include the constant
SIDin all your links etc – this is defined when you callsession_start()and is a string in the format of a URL parameter.