Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning: session_start(): Cannot start session when headers already sent

Tags:

php

wordpress

Im getting an error in my wp-debug log saying "PHP Warning: session_start(): Cannot start session when headers already sent in ...hooks.php on line 228". Here is a code snippet from the file

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

session_start(); is on 228. I have read that session_start should be the first line of code to be executed in the file. Will this not affect the functionality of the code? (I have zero PHP experience)

like image 479
user2730011 Avatar asked Jan 03 '23 18:01

user2730011


1 Answers

Move the session_start() to top of the page. and ob_flush();in footer or end of the script.

<?php
@ob_start();
session_start();
?>
like image 77
Rahul Avatar answered Jan 05 '23 15:01

Rahul