Session is not starting

I’ve read the usage of session() in WordPress from here and here. And I placed the following code into the very starting of my functions.php:

/**
*   ENABLING SESSION TO THE SITE
*   Thanks: Shazzad
*   Source: http://stackoverflow.com/a/16119876/1743124
*/

function register_session() {

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

add_action( 'init', 'register_session' );

But I can’t work with session because that code is failing to start the session. Finally I placed only

session_start();

at the very beginning of my functions.php and it’s working fine. I’m using WP 3.9.1.

Is there can be anything wrong, if I proceed with my project running the session start barely at the very beginning?

Read more here: Session is not starting

Leave a Reply

Your email address will not be published. Required fields are marked *