Skip to content
Advertisement

PHP Store User Data without Sessions

Is there anyway to store users data such as userid, email, etc to be accessible from all pages of a website after they have logged in, but without using sessions or cookies?

For example:

JavaScript

after they login at login.php

JavaScript

now, how do I access $currentUser from another page, such as index.php if I shouldn’t use sessions or cookies at all?

so that I could do the following in index.php:

JavaScript

i asked a similar question before, here, but the answers didn’t fulfill my needs.

Advertisement

Answer

If you’re over-the-top gung-ho with regards to OOP and refuse to directly interact with sessions/cookies, I’d strongly suggest you simply encapsulate sessions instead of remaking them. Even something as simple as this:

JavaScript

Easily adaptable if you want to store the data clientside – in a cookie – instead of just storing the session id client side (which is what this does).

Edit: Also, teasing aside with regards to OOP, if your code is all very OOP, this is actually a genuinely good way to keep your code clean – not just a way to satisfy your OOP-hungry cravings as I implied above 😉

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement