Before using any frameworks I have kept track of logged in users using $_SESSION
from PHP and I was wondering whether there were any other ways to accomplish the same thing in a more elegant way.
I saw an answer on stackoverflow that looked interesting.
I heard about something called tokens (which I understand to be a string) and I noticed it in the URL,but I would like to know:
- what is the purpose of the token?
- how to generate it?
- do I have to update it in the database when the user has logged out ?
- Is it a good practice to create a cookie with the token and check against it?
As far as I know users can restrict cookies being created.
...And I was wondering if (for example using ZF2) I would like to restrict the access for user on certain pages if he is not logged in. I thought I could encapsulate the logic in a service class. What seems pretty redundant is that in each module I want to use the service I would have to do a check something like isUserLoggedIn()
and decide what to do
(if not logged in maybe redirect to the login page) and this doesn't seem very DRY.