Wordpress/PHP: Problems keeping $_SESSION variable when changing page

Asked

Viewed 46 times

-1

I have the code below in the same file:

add_action( 'init', 'iniciaSessao', 1 );
function iniciaSessao() {
    if(!session_id() ) {
        session_start();
    }
}

function info() {
$_SESSION['nome'] = 'meu nome';
}

info();
//session_regenerate_id(true);
wp_redirect($minhaUrl);
exit();

By going to the website homepage (where you are redirecting) and using print_r($_SESSION['nome']); the information set does not appear.

NOTE: the following error message appears when uncommenting the session_regenerate:

session_regenerate_id(): Cannot regenerate Session id - headers already sent

1 answer

0


The problem was that the redirect led to another domain (localhost to localhost ip) making wp believe it was another domain and clear the session and cookies.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.