PHP Session unsetting
Permalink
Hi All,
C5 is turning out to be an excellent framework for me, many thanks.
However I have one small problem. I'm converting an existing website in to a C5 managed site, and on the login page, I used to make PHP clear my session variables.
I use the following code in my C5 header file:
unset($_SESSION['my_sesh']);
unset($_SESSION['other_session']);
But the above seems not work. The sessions still remain active.
Is there some special place I should put this code? Or am I missing something here. This technique used to work fine when I was not using C5.
Many thanks in advance for your help,
Seb
C5 is turning out to be an excellent framework for me, many thanks.
However I have one small problem. I'm converting an existing website in to a C5 managed site, and on the login page, I used to make PHP clear my session variables.
I use the following code in my C5 header file:
unset($_SESSION['my_sesh']);
unset($_SESSION['other_session']);
But the above seems not work. The sessions still remain active.
Is there some special place I should put this code? Or am I missing something here. This technique used to work fine when I was not using C5.
Many thanks in advance for your help,
Seb
The code you're calling doesn't unset the session -- it only unsets variables contained in the session. Concrete5 sets the session and has its own variables in there that it uses, so you shouldn't be trying to start or stop the entire session yourself as it may mess up other parts of the system (but unsetting your own variables that you've declared is fine -- just don't expect it to entirely clear the session).
I understand this, but what I'm finding is that a PHP session that is set outside of the C5 'ecosystem' (but in the same domain/site) is not accessible when viewing pages created by C5 - and vice-versa.
There must be a reason for this - could anyone help enlighten me please?
Thanks again,
Seb
There must be a reason for this - could anyone help enlighten me please?
Thanks again,
Seb
Sessions in C5 are... Well weird, to say the least. Check out my latest problem/post - you might find it helpful:
http://www.concrete5.org/community/forums/customizing_c5/c5-fails-t...
http://www.concrete5.org/community/forums/customizing_c5/c5-fails-t...
Good lord, what on earth?
So how can I access my sessions from within C5? This seems like a pretty fundamental issue.
Is there some sort of top level include where I can play with my sessions within C5?
So how can I access my sessions from within C5? This seems like a pretty fundamental issue.
Is there some sort of top level include where I can play with my sessions within C5?
Well, basically what you do is (anywhere):
And then in the script that needs the variable:
From what I have been able to gather, then the session_start() call might not be necessary at all. This approach works, with the one caveat that in certain cases (as described in my post) C5 doesn't generate the CONCRETE5 cookie, and then you're screwed.
session_id($_COOKIE['CONCRETE5']); session_start(); $_SESSION['YOURSESSIONVARIABLE'] = "your value";
And then in the script that needs the variable:
session_id($_COOKIE['CONCRETE5']); session_start(); echo $_SESSION['YOURSESSIONVARIABLE']; //This will output "your value"
From what I have been able to gather, then the session_start() call might not be necessary at all. This approach works, with the one caveat that in certain cases (as described in my post) C5 doesn't generate the CONCRETE5 cookie, and then you're screwed.
Thanks for the examples, but it doesn't work for me unfortunately.
I don't set my session in the way you described, so therefore when trying to read that value, it still doesnt work.
I cant understand what is happening to my session. Why on earth is it not available at any point in the site? (just in a specific area).
I don't set my session in the way you described, so therefore when trying to read that value, it still doesnt work.
I cant understand what is happening to my session. Why on earth is it not available at any point in the site? (just in a specific area).
Hmm,
Ok could you show me your code? That is, the code responsible for setting the value(s) and the code that needs to read them from the session?
That might clear things up :)
Ok could you show me your code? That is, the code responsible for setting the value(s) and the code that needs to read them from the session?
That might clear things up :)
BUMP