ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
923 stars 219 forks source link

PHP Warning: session_start() #4272

Open fotan opened 1 year ago

fotan commented 1 year ago

PHP Log is filling up with these.

PHP Warning: session_start(): Cannot start session when headers already sent in /home/customer/www/xxxxxxxx/public_html/wp-content/plugins/unyson/framework/helpers/class-fw-session.php on line 13

zhelnitskiy commented 1 year ago

here, too

PHP Warning: session_start(): Session cannot be started after headers have already been sent in /.../wp-content/plugins/unyson/framework/includes/hooks.php on line 259

The problem is still relevant

bakkbone commented 1 year ago

+1

The plugin also causes this in Site Health:

An active PHP session was detected

Performance

A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.

yarlevi commented 1 year ago

same issue here, have you found a fix? image

     * Start the session before the content is sent to prevent the "headers already sent" warning
     * @internal
     */
    function _action_fw_flash_message_backend_prepare() {
        if ( apply_filters( 'fw_use_sessions', true ) && ! session_id()  ) {
            **session_start();**
        }
    }

            /**
             * In ajax it's not possible to call flash message after headers were sent,
             * so there will be no "headers already sent" warning.
             * Also in the Backups extension, are made many internal ajax request,
             * each creating a new independent request that don't remember/use session cookie from previous request,
             * thus on server side are created many (not used) new sessions.
             */
            ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
            &&
            ! session_id()
        ) {
            **session_start();**
        }
    }
Spleeding1 commented 1 year ago

I dropped this into the plugin. Hopefully they can make this permanent. stackoverflow.com

Changed session_start(); to session_start(['read_and_close' => true,]); in:

unyson/framework/helpers/class-fw-session.php line 13 unyson/framework/includes/hooks.php lines 229 and 259