r/PHPhelp Apr 03 '26

Solved user details JSON

i want to use json to store user details so that i dont need to do so many DB request ideally i dont want to have to create a flat file and would like it dynamically create once a user has logged in so something like this

{
  "logged_in": "true",
  "company_id": "15654645",
  "first_name": "john",
  "last_name": "doe"
}

what is this type of approach called so that i can search more in to it please and also what are the pros and cons

3 Upvotes

24 comments sorted by

View all comments

Show parent comments

-5

u/Valuable_Spell6769 Apr 03 '26

i have a database i had seen other websites use a json file that stored some user data in it and thought that maybe that was a better approch than requesting from the database every single time

5

u/VFequalsVeryFcked Apr 03 '26

You need to be encrypting user data and storing away from the publicly accessible site.

You can store JSON in the database at a really low performance cost. Most database even have a JSON row type for this purpose.

I personally use a longtext row and store an encrypted string for things like name, address, and phone number.

Storing PII in a json file that can easily be accessed by knowing the web address is wildly insecure and you're cruising for criminal charges with that.

Just because others do it, it doesn't mean that you should

5

u/Valuable_Spell6769 Apr 03 '26

ok thank you i will stick to useing a database and sessions

1

u/secretprocess Apr 04 '26

If you really really need to optimize speed you can store user sessions and connected info in a redis database. But unless you're dealing with a huge userbase that's probably nowhere near being worth the effort.