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

-1

I have the following code 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();

When you go to the homepage of the site (where you are redirecting) and use print_r($_SESSION['nome']); , the information set does not appear.

NOTE: The following error message appears when uncommenting session_regenerate :

  

session_regenerate_id (): Can not regenerate session id - headers already sent

    
asked by anonymous 04.09.2018 / 17:33

1 answer

0

The problem was that the redirection led to another domain (localhost to localhost ip) causing the wp to believe that it was another domain and cleared the session and cookies.

    
09.09.2018 / 13:37