Skip to content

Check if there is a valid session before messing with session ini values#15742

Closed
PhilETaylor wants to merge 7 commits intojoomla:stagingfrom
PhilETaylor:joomla-cms-15680
Closed

Check if there is a valid session before messing with session ini values#15742
PhilETaylor wants to merge 7 commits intojoomla:stagingfrom
PhilETaylor:joomla-cms-15680

Conversation

@PhilETaylor
Copy link
Copy Markdown
Contributor

Closes #15680
Closes #12153
Check if there is a valid session before messing with session ini values
(NOT TESTED, coded on sight only - please test!)

Closes #15680

Check if there is a valid session before messing with session ini values
(NOT TESTED, coded on sight only - please test!)
{
// Disable transparent sid support
ini_set('session.use_trans_sid', '0');
if (session_id() === "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really have to do this we should be checking either $this->isStarted() or $this->getId(). Although I really feel like this is just a edge case workaround and not something that should exist in production code (I'm not aware of any other session API that has this level of checks).

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented May 2, 2017

This is nothing more than a wrapper to session_id() anyway :)

Better to use the abstractions than hardcode stuff 😉

You have my opinion on the matter, whether others agree or not is to be determined. Honestly, session packages are one part of the PHP ecosystem that lack interoperability and part of it does boil down to the internal uses of ini_set() (at least in the cases of our own Session APIs, Symfony, and Aura; don't have the time at the moment to look for other packages and review those).

@csthomas
Copy link
Copy Markdown
Contributor

csthomas commented May 2, 2017

IMO this place would be better for such ini_set() https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/session/session.php#L132

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented May 2, 2017

Not really, the intent with the abstraction layers is to make it so that configuration changes that don't have to be made for an environment aren't. If you ran a custom app off the CMS app stack using JSession you could use a different JSessionHandlerInterface implementation that either doesn't need that ini_set() call or makes different ones altogether.

JSession (and in 4.0 the Framework's Joomla\Session\Session) are really just the interface for folks to read/write data from the session store. The abstraction layers underneath it (storage and handler) are the internal details where these configs start getting made. So JSession should rightfully be as ignorant to outside influences as practical.

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@csthomas
Copy link
Copy Markdown
Contributor

csthomas commented May 5, 2017

@PhilETaylor I have a new suggestion.

What about move it to start() method?

@PhilETaylor

This comment was marked as abuse.

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented May 5, 2017

That could be viable.

@PhilETaylor

This comment was marked as abuse.

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented May 5, 2017

JSessionHandlerJoomla::start() please. Unless there's some absolute critical reason it HAS to be in JSession::start().

@PhilETaylor

This comment was marked as abuse.

@csthomas
Copy link
Copy Markdown
Contributor

csthomas commented May 5, 2017

Great, for me ok

@csthomas
Copy link
Copy Markdown
Contributor

csthomas commented May 5, 2017

@mbabker I thought about JSessionHandlerJoomla::start(), I forgot to mention class name.

@brianteeman brianteeman modified the milestone: Joomla 4.0 Jun 8, 2017
@wetken
Copy link
Copy Markdown

wetken commented Sep 11, 2017

I have this issue using Joomla 3.7.5. Is there anything I can do to resolve it until the next release?
(I'm using an unconventional setup, I accept that, but I'm also fighting a time constraint.)

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /home/.../libraries/joomla/session/handler/joomla.php on line 46

Warning: Cannot modify header information - headers already sent by (output started at /home/.../libraries/joomla/session/handler/joomla.php:46) in /home/.../libraries/joomla/session/handler/joomla.php on line 104
Error displaying the error page: Application Instantiation Error: Failed to start the session because headers have already been sent by "/home/.../libraries/joomla/session/handler/joomla.php" at line 46.

@ghost
Copy link
Copy Markdown

ghost commented Sep 11, 2017

@wetken please don't post same Comment double like in #15680

@csthomas
Copy link
Copy Markdown
Contributor

@wetken It should be easy to copy this file and replace in 3.7.5. This PR was designed for 3.7.
At J3.8 this file was moved to other place.

If you use joomla git on linux and you have shell access you can add this changes by command:

curl https://patch-diff.githubusercontent.com/raw/joomla/joomla-cms/pull/15742.diff | git apply

@wetken
Copy link
Copy Markdown

wetken commented Sep 11, 2017 via email

@wetken
Copy link
Copy Markdown

wetken commented Sep 11, 2017 via email

andrewpthompson added a commit to andrewpthompson/joomla-cms that referenced this pull request Jan 2, 2018
This is a test patch based on PR joomla#15742 updated for J3.8 to attempt to resolve CiviCRM's cron errors on J3.8.

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /var/www/html/membership/libraries/joomla/session/handler/joomla.php on line 48
Error: Failed to start application: Failed to start the session because headers have already been sent by "/var/www/html/membership/libraries/joomla/session/handler/joomla.php" at line 48.
andrewpthompson added a commit to andrewpthompson/joomla-cms that referenced this pull request Jan 2, 2018
This is a test patch based on PR joomla#15742 intended to fix a problem that the CiviCRM extension has been encountering since J3.8.0 with its CLI cron script not working on PHP 7.0:
Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /var/www/html/membership/libraries/joomla/session/handler/joomla.php on line 48
Error: Failed to start application: Failed to start the session because headers have already been sent by "/var/www/html/membership/libraries/joomla/session/handler/joomla.php" at line 48.
@andrewpthompson
Copy link
Copy Markdown

@PhilETaylor and @mbabker I would like to ask you guys if there is still any plan to implement this PR? It would resolve a problem in the CiviCRM extension that has been present since Joomla 3.8.0. As CiviCRM has far more Drupal & Wordpress users and developers than it does Joomla, I've been trying to get this fixed out of necessity.

CiviCRM has a cron script that bootstraps the CMS and runs CiviCRM's scheduled jobs. In some environments (PHP 7) it fails to run due to:

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /var/www/html/membership/libraries/joomla/session/handler/joomla.php on line 48
Error: Failed to start application: Failed to start the session because headers have already been sent by "/var/www/html/membership/libraries/joomla/session/handler/joomla.php" at line 48.

CiviCRM's cron.php is doing a session_start() and this occurs before it calls JPluginHelper::importPlugin('civicrm'); which leads to Joomla doing the ini_set() in libraries/joomla/session/handler/joomla.php when there is a session already active.

Almost the same thing happens with its REST API and again it does a session_start() before bootstapping Joomla.

I updated Phil's PR for Joomla 3.8 to test this and it does resolve these particular problems (although I don't really know if it's correct for CiviCRM to be doing the session_start() in the first place).

@PhilETaylor

This comment was marked as abuse.

@andrewpthompson
Copy link
Copy Markdown

@PhilETaylor Would you be prepared to update your PR to resolve the conflicts so that it's more likely to get tested by other people? Thanks.

@wetken
Copy link
Copy Markdown

wetken commented Mar 5, 2018 via email

@andrewpthompson
Copy link
Copy Markdown

@wetken My question was to PhilETaylor, the author of this pull request.

@roland-d
Copy link
Copy Markdown
Contributor

@PhilETaylor Can you fix the conflicts so I can get it tested over the next two days?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15742.

@PhilETaylor

This comment was marked as abuse.

@roland-d
Copy link
Copy Markdown
Contributor

@PhilETaylor Thank you for replying, I will see what we can do.

@PhilETaylor

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants