I’ve got a user log in form which sets a cookie and enables members only content.
This works ok for all pages in the root folder of my site. I’ve confirmed the session variable exists etc.
However, when I try and check for the session variable in a script that is in a subfolder the session variable does not exist. I’ve looked at similar questions which suggest an answer and to add an ‘/’ in the params.
This is my session start:
session_set_cookie_params(2*7*24*60*60,'/');
This is before session_start()
In phpinfo the session cookie path is also set to ‘/’
The session exists at root level not for sub folders.
What have I missed and how can I resolve? I want to avoid passing a variable to the script if possible
Thank you.
Ok – I solved this one!
In my script that was trying to access the session I did not have:
session_name(mysessionName)
or
session_start()
Apparently you need to re-initiate the session in the script in the other paths to get it to work then do session_start
session name must come before session start
Yay!!