Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

May I save user id inside $_SESSION variables?

Working on very big project and trying to create optimal database usage. I heard that it's not recomended to save user id's in $_SESSION variables. I can actually work with only tokens, this tokens are assigned to user id's in database. The problem is, if I will work with only tokens, I need to do 1 extra operation (query) with database inside script. So the question is, may I save user id inside $_SESSION variables to prevent ectra database operations? How "dangerous" it might be?

Thx in advance.

like image 273
heron Avatar asked Jun 07 '26 18:06

heron


1 Answers

Yes, you may. The session is stored on the server and therefore just about as safe as any other server-side storage.

like image 198
deceze Avatar answered Jun 09 '26 07:06

deceze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!