What is the recommended way to start a php session in an EE module.

I am using EE 2.9.4 and have a custom module. In the constructor I call session_start(). When I look at the cookie that gets created the cookie path is wrong. It is set to the path of the page instead of "/".

When I call session_start in a plain php app the default behavior of session_start is to set the cookie path at root "/".


ExpressionEngine sets the PHP session cookie to use identical parameters to match the application's cookie settings. In v3, you can find this under Settings > Security & Privacy. In v2, it would be in Admin > Security and Privacy > Cookie Settings.

If the Cookie Path is left blank, then PHP will base the cookie off of the path in the URL at the time the cookie is set. You can make sure all of your cookies are available at the root by setting the Cookie Path to /.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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