Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data should I store in a PHP session?

I am building a small application that users can log into using CodeIgniter

My question is, when a user logs in, is it advisable to store a lot of the users personal information in the session (like their user id, name, email and telephone number). Or should I try leave personal information out and just keep their user id in the session only?

I don't want to have to make database queries constantly to get some or the users basic information.

Update

I will be using a database to store all their information, I just want to know when they log in, is it advisable to keep their data stored in a session as well as the database?

Thanks

like image 296
Peter Stuart Avatar asked Oct 12 '25 03:10

Peter Stuart


1 Answers

You should only keep temporary data in sessions that tracks that current user. Anything else should stay hidden in the database until it's needed.

like image 142
Maelish Avatar answered Oct 14 '25 17:10

Maelish