pick private user id of a session

Asked

Viewed 36 times

0

I want to get an id of a user who is recorded in the session, I’m trying to serialize the object when created:

$_SESSION['usuario'] = serialize($objUsuario);

and to recover I tried to use:

echo unserialize($_SESSION['usuario'])->getIduser();

returns error:

Fatal error: main(): The script tried to execute a method or access a Property of an incomplete Object. Please ensure that the class Definition "pojoUsuario" of the Object you are trying to Operate on was Loaded before unserialize() gets called or provide an autoloader to load the class Definition in

If I give a var_dump($_SESSION['usuario']); die();

returns:

add-data.php:4:string 'O:11:"pojoUsuario":8:{s:19:"�pojoUsuario�iduser";s:1:"1";s:21:"�pojoUsuario�username";s:8:"nanous";s:18:"�pojoUsuario�senha";s:32:"1f32aa4c9a1d2readssdsdsdsddds6a04";s:18:"�pojoUsuario�email";s:20:"[email protected]";s:25:"�pojoUsuario�frasesecreta";s:14:"dogs";s:21:"�pojoUsuario�resposta";s:4:"S#hu";s:17:"�pojoUsuario�flag";s:1:"1";s:22:"�pojoUsuario�datasenha";s:10:"2018-07-24";}' (length=398)

I need to get the data stored on Session, such as user name and iduser and I’m not getting.

1 answer

3


In the file you’re giving the unserialize($_SESSION['usuario']) need to have class definition pojoUsuario also.

A tip is to include the file that defines this class, for example:

require_once 'PojoUsuario.php'; // inclui definição da classe

session_start();

echo unserialize($_SESSION['usuario'])->getIduser();

More information and tips on PHP documentation here.

  • 1

    True, there was no attempt on that detail. Thank you.

Browser other questions tagged

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