'Use Sessions in wordpress

I'm using wordpress to create my application. In this application I am using wordpress login and trying to use Sessions.

The pages I'm creating new in wordpress I'm creating in the directory where we have wp-login.php.

To use the sessions I'm putting this code inside the theme's functions.php, but I'm creating the pages outside the theme directory as I explained above:

session_start();
$_SESSION['usuarioId'] = $user_ID;;
$_SESSION['usuarioNome'] = $user_identity;
$_SESSION['email'] = $user_email;
$_SESSION['login'] = $user_login;
$_SESSION['image'];
function register_my_session(){
    if(! session_id()) {
        session_start();
    }
}

When I log in, I immediately redirect to a page I created, with the name home.php, which starts this page with the following code:

session_start();
$_SESSION['usuarioId'];
$_SESSION['usuarioNome'];
$_SESSION['email'];
$_SESSION['login'];

if(!isset($_SESSION['usuarioId']) || !isset($_SESSION['usuarioNome']) || !isset($_SESSION['email'])){
header('Location: https://gestao.centropadreangelo.pt/login');
exit;
}

Now when I login and redirect to the home.php page, the sessions are empty. But if you force access to the wp-admin page and then go back to the home.php page, it returns the correct values ​​in the sessions.

I intend that soon when making the redirection of the login for the home.php return soon the values ​​in the sessions.

Can you help to solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source