note 85224 added to book.session

From: Date: Thu, 21 Aug 2008 08:41:18 +0000
Subject: note 85224 added to book.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-143698@lists.php.net to get a copy of this message
Cant believe this problem isnt described herein. I wondered why my session-variables lost their values when going from first site to second site. Both had a session_start();. A session is working only on one domain. Subdomains dont use the Session of the maindomain. That means if someone comes to your site at yourdomain.com and the session is started there and then clicks a link where he is lead to www.yourdomain.com then the old session isnt working there anymore. Because www. is a subdomain. In the practice that will mean a lot of lost sessions only because webmasters dont know this behaviour. I have never read a word about this in manuals or somewhere... The solution is to put this code before the first session_start(); ini_set("session.cookie_domain",substr($_SERVER[HTTP_HOST],3)); Now it works. At the second place of parameters has to come in ".yourdomain.com" (with a dot before). With that the subdomains will use the same session like the maindomain. In this example domainname taken from Server-variable. Greetings! Sebastian ---- Server IP: 212.124.37.9 Probable Submitter: 77.21.42.4 ---- Manual Page -- http://www.php.net/manual/en/book.session.php Edit -- https://master.php.net/note/edit/85224 Del: integrated -- https://master.php.net/note/delete/85224/integrated Del: useless -- https://master.php.net/note/delete/85224/useless Del: bad code -- https://master.php.net/note/delete/85224/bad+code Del: spam -- https://master.php.net/note/delete/85224/spam Del: non-english -- https://master.php.net/note/delete/85224/non-english Del: in docs -- https://master.php.net/note/delete/85224/in+docs Del: other reasons-- https://master.php.net/note/delete/85224 Reject -- https://master.php.net/note/reject/85224 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143698) next »