C5 Session variable access within other PHP scripts

Permalink
Hi All.

I have a couple of custom functions in my C5 site that run some simple PHP scripts that are located in the template folder. At the start of the script I do the usual session_start(); ( and I have even resorted to using the session_id($_COOKIE['CONCRETE5']); session_name("CONCRETE5"); session_start(); that has been listed in some of the other posts on the subject. )

I'm running this to see what's going on:

print_r($_SESSION);
print ('Name: ' . session_name());
print ('ID: ' . session_id());

The net result is that I seem to have sessions with the same name, same ID, but different contents, and nothing is accessible between the scripts / pages. Obviously this isn't what I'm after: I need to be able to pass information between them and the $_SESSION variable is the ideal place to do this.

There are a number of posts on this subject in the forums - and no real answers to what is going on. Is there something that I need to run at the start of the page to connect to C5 and allow it to manage the session (Joomla has this - its about 5 lines of code that connects you to the session)?

Any help much appreciated. Or am I going to have to move this project to another CMS?

 
exchangecore replied on at Permalink Reply
exchangecore
Could you maybe elaborate a bit more? Are you trying to use a session variable in c5 that is set in some other app, or vice versa? Do you have full page cache enabled by chance?
phdigital replied on at Permalink Reply
I've disabled all caching - I wondered if that was the cause.

What I have is a C5 CMS Page, that calls an external PHP script, which returns it's values to the C5 CMS page using the $_SESSION variable.

When the CMS page loads, I can see one session variable with the usual C5 stuff in it, when the external page loads (which is stored in the theme folder), even if I set the session name and ID to be the same, I see completely isolated contents in the session variable, which are dropped when the site returns to the CMS page.
phdigital replied on at Permalink Reply
I think I have the answer.

Lines 18-20 of the concrete/startup/session.php change the default location in which the session is actually stored. If I comment out these lines, the data is shared correctly.
phdigital replied on at Permalink Reply
Although I can't find where DIR_SESSIONS is set ...
JohntheFish replied on at Permalink Reply
JohntheFish
If you run your external scripts as concrete5 tools, then you will have access to the environment including the session.