On PHP ≥ 7.2, these warnings show up in the logs at admin/reports/dblog:

  • Warning: session_id(): Cannot change session id when headers already sent in drupal_session_initialize() (line 266 of includes/session.inc).
  • Warning: session_set_save_handler(): Cannot change save handler when headers already sent in drupal_session_initialize() (line 242 of includes/session.inc).

Steps to reproduce:

  1. Enable page cache;
  2. Enable Better Statistics module;
  3. Enable access log at admin/config/system/statistics;
  4. As anonymous user, load a cached page which is longer than PHP output buffer, or of any length if PHP output_buffering is disabled.

In this case, better_statistics_exit() is initializing a session after the page has already been sent.

The proposed patch no longer attempts to initialize a session in better_statistics_exit(). Requests being served from the page cache will have empty string stored in the sid column of the accesslog table, which is what session_id() returns when there is no session.

CommentFileSizeAuthor
session-warning.patch494 bytesmfb

Comments

mfb created an issue. See original summary.

avpaderno’s picture

Title: [PHP ≥ 7.2] "session_id(): Cannot change session id" » "session_id(): Cannot change session id"
Issue tags: +PHP 7.2, +PHP 7.3