最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PHP session not staying alive. headers already sent

programmeradmin1浏览0评论

I'm having trouble keeping my session alive, it times out after 3 hours (our desired custom timeframe) regardless of user activity. It used to keep the session alive for the next 3 hours every time somebody changes pages on the site. Now i get the "Headers already sent" error in the error log every time somebody changes pages. The session is created correctly but it cant be updated without the headers already sent error occurring.

My session_start function is added to wordpress init action, as suggested in the wordpress docs. I've simplified the code to the bare minimum and still no success.

function checkmateStartSession()
{
    if(!session_id())
    {
        session_name('SESCHECKMATEID');
        session_start(['cookie_lifetime' => 300]); // 5 minutes for testing purposes
    }
}
add_action('init', 'checkmateStartSession', 1);

I've tried output buffering with ob_start() before the session_name() line and ob_end_flush() after session_start() to no avail.

I've disabled the plugins folder, problem persisted.

Changing the theme deactivates the functions.php file in which my session code lives, so the code goes back to wordpress default session code. Am I missing something in a newer update? This code used to work.

发布评论

评论列表(0)

  1. 暂无评论