Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Doing some testing, and stumbled across the "CraftSessionId" cookie...

What's the difference between CraftSessionId and a normal PHP session? Is there any difference at all? What's the best way to refer to the current session?

share|improve this question
Per my conversation with Brad and some additional digging around, I found that you can't (read: shouldn't) use session_start()... Instead, you'll want to use craft()->getSession() to trigger a new session (or revive an existing one). Once you've done that, you'll be able to get your session ID normally via session_id(). – Lindsey D Jul 28 '14 at 3:25
up vote 3 down vote accepted

They are one in the same.

Craft simply renames it to "CraftSessionId" rather than the default "PHPSESSIONID".

The only additional things we do to it is set the "httpOnly" flag so that JavaScript can't read it and change the place it is saved to by default (varies per server) to craft/storage/runtime/sessions.

You can see that in action in HttpSessionService, which extends Yii's CHttpSession, which is a convenient wrapper for PHP's session functionality.

share|improve this answer
Thanks Brad! Am I also correct in thinking that session_start is automatically called by Craft every time a page is loaded? – Lindsey D Jul 24 '14 at 21:51
It'll be called the very first time HttpSessionService\CHttpSession get loaded and initialized in a request. – Brad Bell Jul 24 '14 at 21:53
Sweet, thanks Brad! – Lindsey D Jul 24 '14 at 21:54
"JavaScript can't read it" ... Very good to know, actually impacts what I'm working on! Sounds like I'll need to have JS ping a Controller (which will then access the session in PHP). – Lindsey D Jul 24 '14 at 21:55
Hah, it actually used to be open to JS (up until 2.0, I think), but you know... security and whatnot. – Brad Bell Jul 24 '14 at 22:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.