Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "An active PHP session was detected" critical warning in wordpress

Tags:

wordpress

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.

like image 355
Mohit Sharma Avatar asked Oct 15 '20 17:10

Mohit Sharma


People also ask

How do I close a PHP session in WordPress?

Forcing A Session To End We can use a custom hook to end a session anywhere within the theme by using the do_action function provided by WordPress to call the end_session function we created above. 1: In the functions. php file we would add the following. add_action('end_session_action', 'end_session');

What is an active PHP session?

“An active PHP session was detected. 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.”


6 Answers

In most cases, the real reason of the above errors is the incorrect mechanism for using PHP sessions within plugins or themes when they are using the session_start() function.

Now you need to identify what plugin cause this issue by deactive your plugin one by one.

Then in that plugin, you need to find a piece of code similar to this:

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

then change it to:

if ( !session_id() ) {
    session_start( [
        'read_and_close' => true,
    ] );
}

Then you are done. In most cases, this will fix the issue. Good luck!

like image 84
thống nguyễn Avatar answered Oct 21 '22 03:10

thống nguyễn


Had the same issue due to WP Hotel Booking plugin use. I fixed it! Took me a while to find a plugin it caused and editing the plugin .php didn’t help. But I fixed it adding a snippet of code to functions.php of the CHILD theme:

function mymodule_curl_before_request($curlhandle){
session_write_close();
}
add_action( ‘requests-curl.before_request’,’mymodule_curl_before_request’, 9999 );

Found a solution here: https://de.wordpress.org/support/topic/curl-error-28-und-andere-fehlermeldungen/

like image 7
Eugenia Filippova Avatar answered Oct 21 '22 05:10

Eugenia Filippova


Often this critical issue is caused by conflict in SESSION when using the PHP session_start() function. For example I have used a Calculation plugin in Wordpress and after Wordpress version update this error occured. So I detected the plugin which causes this issue as activated/deactivated plugins one by one.

SOLVING these errors: In File manager of my site I got the .php files of the plugin and searched for session_start() function. Where it was used after it I used this function in a row session_write_close();

Source of the function

Regards!

like image 2
rossirm Avatar answered Oct 21 '22 03:10

rossirm


To chime in with my own experience here, this very issue was resolved by turning off the “cross sell pop up” module of Shopengine Pro. Indeed there’s a session start in the php. I have notified them about this today. Maybe it’ll help someone else meantime!

like image 1
David M. Avatar answered Oct 21 '22 04:10

David M.


I found out that you get these critical health warnings when you install a plugin or a plugin Adon and fail to complete its setup to the end. So the simplest solution is to deactivate the plugin or complete the plugin set-up. My errors were caused by a Woocommerce Adon which I deactivated and when I refreshed the health status the two issues were gone. I hope this helps.

like image 1
Philip Agutu Avatar answered Oct 21 '22 04:10

Philip Agutu


If you tried the above and it's not working try to change the php version from your hosting's CPanel I had the same error ande i changed the php version from 7.4 to 7.3 and it all went well

like image 1
randy Avatar answered Oct 21 '22 03:10

randy