note 91298 added to function.session-start
| From: | gilthansNOSPAN at gmail dot com | Date: | Thu, 04 Jun 2009 12:55:09 +0000 |
| Subject: | note 91298 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156356@lists.php.net to get a copy of this message | ||
Two different files don't access the same session?
It can only mean one thing: they aren't on the same directory level.
Examples:
a) One is under https, and one is under http. (very common and annoying error)
b) One is under /, another is under /dir1, and /dir1 was first to run. The cookie created by the
session is for /dir1 and deeper only, so the other script can't read it; it sees no session so
it starts a new one.
Solutions?
1) Session start should always happen at root dir. If one of your scripts discovers user is not
logged in, for example, use session_destroy() and send him to the login in the root dir. Scripts
that use session without requiring login needs more creative solutions, like redirecting to the root
dir, setting the session, and redirecting back.
2) Use SID from page to page, instead of cookies. The upside is that this also works with
http/https. The downside is very ugly URL codes and more difficult maintainability ('which
pages links to gallery.php without using SID?!').
----
Server IP: 82.80.248.162
Probable Submitter: 212.143.222.100
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- https://master.php.net/note/edit/91298
Del: integrated -- https://master.php.net/note/delete/91298/integrated
Del: useless -- https://master.php.net/note/delete/91298/useless
Del: bad code -- https://master.php.net/note/delete/91298/bad+code
Del: spam -- https://master.php.net/note/delete/91298/spam
Del: non-english -- https://master.php.net/note/delete/91298/non-english
Del: in docs -- https://master.php.net/note/delete/91298/in+docs
Del: other reasons-- https://master.php.net/note/delete/91298
Reject -- https://master.php.net/note/reject/91298
Search -- https://master.php.net/manage/user-notes.php