Check for valid session before messing with session ini#21260
Conversation
… is no error thrown.
|
@niklas-deworetzki-thm #15742 is an Pull Request, so you wan't to close this? |
|
@franz-wohlkoenig i guess it's because of this #15742 (comment) Phil is not able to fix conflicts these days |
|
@jeckodevelopment thanks, so all fine. |
| ini_set('session.use_only_cookies', 1); | ||
| } | ||
| } | ||
|
|
| { | ||
| return; | ||
| } | ||
|
|
|
|
||
| return parent::start(); | ||
| // Only change ini if there is no active session. | ||
| if (!headers_sent() && session_id() == '') |
There was a problem hiding this comment.
Use tabs and not spaces to indent.
| protected function setCookieParams() | ||
| { | ||
| if (headers_sent()) | ||
| // We can't change cookie params, if there is a valid session or headers have already been sent. |
There was a problem hiding this comment.
might seem pedantic but please remove the , from this comment as it changes the meaning of the sentence.
|
I'm happy for 3.8 to ignore I think - especially as in 3.x we don't have good session management in the CLI scripts - and just to tighten the screw in 4.x |
|
Okay, that's fine. So we just need some testers before we can finally merge this PR This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21260. |
@niklas-deworetzki-thm correct. Every Pull Request need 2 successfully Tests (not by PR-Dev.) before Maintainer decide if PR gets merged. |
|
@niklas-deworetzki-thm I have tested this patch on Joomla 3.9.1 and it works as expected. My interest in it is that it would resolve a longstanding problem (since J3.8) with CiviCRM's cron jobs failing because of I am wondering about the other instances of |
|
@niklas-deworetzki-thm can you please comment @andrewpthompson above? |
|
@andrewpthompson I don't know about any other instances of Since those variables should only be changed during Joomlas startup procedure, it is relatively safe to assume no other errors will occur at runtime. |
|
Thanks @niklas-deworetzki-thm. That makes sense. I hadn't seen any problem arise from other instances of |
|
@andrewpthompson please mark your test as successfully > https://docs.joomla.org/Testing_Joomla!_patches#Recording_test_results |
|
I have tested this item ✅ successfully on 1d52b99 Prior to applying the patch I received this error: After applying the patch, no error. No adverse effects seen from the patch. I tested logging in and out of J Admin console and frontend, editing article. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21260. |
|
@PhilETaylor can you please test as Opener of #15742? |
This comment was marked as abuse.
This comment was marked as abuse.
didn't get what this mean. |
|
@PhilETaylor got it and sorry to read. I try to make this better. |
|
It can't be applied: The file marked for modification does not exist: libraries/joomla/session/handler/joomla.php This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21260. |
|
@anibalsanchez did you by chance test this on 4.0? This PR is for 3.9.x. |
|
We are testing on J4. |
one year later … |
|
As Joomla is an application in itself where a session management is completely handled internally, a session should not be started before invoking an index.php. If you want to start the session before the app is loaded, then you can do in Joomla 4 your own session service provider and start the app with that one, so you have full control over the session. I also really suggest to use the web service API to interact nowadays with Joomla from an external application. So I'm closing as this is expected behavior. |

Pull Request for #15742
Original issue closes:
Summary of Changes
Moved
ini_setout of constructor intoJSessionHandlerJoomla::startand added a check to test, if there is an active session, soini_setdoesn't get called. This prevents an error from being thrown, if a PHP session was setup before Joomla! is started.Additionally added a similar check in
JSessionHandlerJoomla::setCookieParams, because the last call inside this functionsession_set_cookie_paramsalso fails, if there is already a PHP session.Testing Instructions
You can test this code by putting a
session_start()statement somewhere, before the Joomla! application starts. For example in the beginning of your index.php or inside a custom php-application using the Joomla! framework.Expected result
No warnings or errors.
Actual result
A warning is displayed, telling you, that you can't change cookie parameters when a session is active:
Warning: session_set_cookie_params(): Cannot change session cookie parameters when session is active in xxx/libraries/joomla/session/handler/joomla.php on line 151Or a warning is displayed, telling you, that you can't change the ini when a session is active:
Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in xxx/libraries/joomla/session/handler/joomla.php on line 48Documentation Changes Required
Manipulating the PHP session outside of Joomla! leads to Joomla! being unable to setup the session by itself. This prevents the cookie params from being set (with and without the fix).
Perhaps there should be a warning, that you should not mess with the session unless you're knowing what you are doing.
@icampus