[Pro Sites] PHP Warning: Cannot start session when headers already sent in /Helper/Session.php

I’m getting this a lot:

PHP Warning: session_start(): Cannot start session when headers already sent in /var/xxx/xxxx.com/public_html/wp-content/plugins/pro-sites/pro-sites-files/lib/ProSites/Helper/Session.php on line 29

And this is what’s happening on line 29 in Session.php:

// Make sure session is started
if ( ! session_id() ) {
session_start();
}

Is it a bug?

Or what else could cause this?

Thanks!

  • Ash
    • Code Norris

    Hello Axel

    This is the correct way to initiate a session:

    if ( ! session_id() ) {
    session_start();
    }

    So, if there is no session ID, only then start the session.

    Seeing the error, it seems there is a conflict. Any plugin or theme maybe initiating session before checking session ID. Would you please run a conflict test? Please deactivate all plugins except pro sites and check if the problem gone. If so, then enable all plugins one by one and find which one is having conflict. You need to do the same with themes as well.

    You can find the flowchart here: https://wpmudev.com/docs/getting-started/getting-support/#chapter-1

    Let us know how it goes. Have a nice day!

    Cheers,

    Ash

  • Axel
    • Design Lord, Child of Thor

    So, if there is no session ID, only then start the session.

    Yes, okay, but what I understand from the error is that it is not the right moment to initiate a session. It should be done before the headers are set… I have no clue when the headers are set though, just saying I didn’t mean that this is not the correct way to start a session… I actually tried one different way – if ( session_id() === "" ) { session_start(); } – but the warning remained the same.

    Would you please run a conflict test?

    Okay, will do that.

  • Axel
    • Design Lord, Child of Thor

    Deactivated all except for Pro Sites.

    Network Activated:

    – Support System > OK

    – WPMU DEV Dashboard > OK

    Activated on main site:

    – Coming Soon & Maintenance Mode by Colorlib (https://wordpress.org/plugins/colorlib-coming-soon-maintenance/)

    Log:

    [01-Mar-2019 06:57:57 UTC] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, class 'CCSM_Customizer' does not have a method 'settings_page' in /wp-includes/class-wp-hook.php on line 286
    [01-Mar-2019 06:57:57 UTC] PHP Notice: Undefined index: theme in /wp-content/plugins/pro-sites/pro-sites-files/modules/premium-themes.php on line 379
    [01-Mar-2019 07:04:47 UTC] PHP Warning: session_start(): Cannot start session when headers already sent in /wp-content/plugins/pro-sites/pro-sites-files/lib/ProSites/Helper/Session.php on line 29

    Deactivated on main site:

    – Coming Soon & Maintenance Mode by Colorlib

    Activated on main site:

    – Google Tag Manager for WordPress > OK

    – Post SMTP > OK

    – WP HTML Mail

    Log:

    [01-Mar-2019 07:14:45 UTC] PHP Notice:  Undefined index: post_smtp_global_settings in /wp-content/plugins/post-smtp/Postman/PostmanAdminController.php on line 172
    [01-Mar-2019 07:15:25 UTC] PHP Warning: session_start(): Cannot start session when headers already sent in /wp-content/plugins/pro-sites/pro-sites-files/lib/ProSites/Helper/Session.php on line 29
    [01-Mar-2019 07:31:23 UTC] PHP Notice: check_ajax_referer was called <strong>incorrectly</strong>. You should specify a nonce action to be verified by using the first parameter. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 4.7.) in /wp-includes/functions.php on line 4667

    Now I wonder if this is caused by Post SMTP or by WP HTML Mail…

    The notice related to Post SMTP is probably the consequence of a known bug that should be solved with the next update… That can be ignored.

    Deactivated on main site:

    – Post SMTP

    – WP HTML Mail

    Network Activated:

    – Branda > OK

    – Defender Pro

    Log:

    [01-Mar-2019 07:37:22 UTC] PHP Warning: session_start(): Cannot start session when headers already sent in /wp-content/plugins/pro-sites/pro-sites-files/lib/ProSites/Helper/Session.php on line 29

    Urgh.

    *Stops activating to report*

    The theme can’t be it, I guess. It’s simply Twenty Seventeen…

    Btw, I notice I forgot to remove the absolute path to /wp-content in my initial post, but can’t edit it anymore.

    Could you remove that?

    Thank you! =)

  • Axel
    • Design Lord, Child of Thor

    Weirdly, I’m having this one a few times now, even though I did not yet reactivate Hummingbird.

    PHP Notice: Undefined index: HTTP_USER_AGENT in /wp-content/plugins/wp-hummingbird/core/modules/class-module-page-cache.php on line 574

    The session warning shows up a few times every hour, while only having Branda, Defender Pro, Support System and the WPMU DEV Dashboard active.

  • Nithin Ramdas
    • Support Wizard

    Hi Axel,

    This is an odd issue, I tested in my system, but wasn’t able to replicate such issue. Just to be sure, the issue occurs when creating a new subsite via Pro Sites in the frontend? or you notice the same even when creating a subsite via backend too? Please do point out if there are any specific steps to replicate it.

    We’ll need to further troubleshoot to see what exactly could be causing this. Could you please send us your websites credentials, so that we could give a closer look.

    You can send credentials by using our secure contact form: https://wpmudev.com/contact/#i-have-a-different-question

    – To Mark to my attention, the subject line should contain only: ATTN: Nithin Ramdas

    -WordPress admin username

    -WordPress admin password

    -login URL

    -FTP credentials (host/username/password)

    -link back to this thread for reference

    -any other relevant URLs

    Please do follow up in the ticket once you have sent the above credentials. Have a nice day. :slight_smile:

    Kind Regards,

    Nithin

  • jcnjr
    • WP Core Meltdown

    Just chiming in here to report that we are seeing numerous entries of the same error in our logs recently:

    [19-Apr-2019 16:18:52 UTC] PHP Warning:  session_start(): Cannot start session when headers already sent in /home/account/public_html/wp-content/plugins/pro-sites/pro-sit
    es-files/lib/ProSites/Helper/Session.php on line 29

    Subscribing to be notified of any possible resolution.

    Axel Did you get this resolved?

  • Axel
    • Design Lord, Child of Thor

    jcnjr, no, sorry, did not get it resolved yet.

    ProSites is currently not active either… and working on something else at the time.

    Might take another while before I get back to it.

    Nithin, sorry I didn’t follow up here yet.

    I would not mind to let you take a look, but I don’t use FTP or SSH passwords…

    I only login with SSH keys.

  • Nithin Ramdas
    • Support Wizard

    Hi Axel,

    Nithin, sorry I didn’t follow up here yet.

    I would not mind to let you take a look, but I don’t use FTP or SSH passwords…

    I only login with SSH keys.

    No worries. If you are still looking for us to troubleshoot the issue further, could I know is there any relevant details you need from us for SSH to work? like a public key?

    You can send any relevant details via the contact form as mentioned in here:

    https://wpmudev.com/forums/topic/pro-sites-php-warning-cannot-start-session-when-headers-already-sent-in-prosites-helper-sessio#post-1381912

    So, that we could follow up via email about what’s being missed etc.

    Have a nice day ahead. :slight_smile:

    Regards,

    Nithin