I learned php by myself and didn't teach anyone, so there are a lot of problems. I hope the experts can help me. First, for example, how to register a session after I log on to the user (I will operate the session ), is to register the session information, how to encrypt the appropriate, how long the validity period is appropriate, and after the seesion is registered, the user in... I learned php by myself, And no one taught me, so there are a lot of problems. I hope you can help me.
First, for example, how can I register a session after a user logs in (I will operate the session), that is, what information should be registered for the session, how can the encryption be appropriate, and how long can the validity period be appropriate?
After the seesion is registered, how can I verify that the session is valid when the user accesses the page?
Reply content:
I learned php by myself, And no one taught me, so there are a lot of problems. I hope you can help me.
First, for example, how can I register a session after a user logs in (I will operate the session), that is, what information should be registered for the session, how can the encryption be appropriate, and how long can the validity period be appropriate?
After the seesion is registered, how can I verify that the session is valid when the user accesses the page?
I think figuring out how the session works will help you write the program
Why does the server know this is the same session when you refresh the page?
SESSID, SESSION (generally) is a file on the server, and SESSID is the file name or other unique identifier.
SESSID is transmitted by COOKIE or QUERYSTRING (the two methods can be set on the apache server)
PHP will put the content in this file (or other methods such as redis or database) into the super global variable $ _ SESSION.
Back to your question:
The login problem is to exchange the user name and password for a token to access private data.
Save the token to $ _ SESSION. When you log on again, you only need to verify whether you have the token and the Token's reliability.
How to Use php session