php - Sessions or cookies? -


I'm creating a platform for most learning, but hopefully there will be a few users in it for a few days.

Are you thinking that users should use sessions or cookies for authentication?

A cookie is small arbitrarily piece of data that the server sends through a header; The customer stores it locally and sends it back to the next request. This mechanism can be used to maintain a request from the next state, although HTTP itself is a stateless protocol. There are two disadvantages of cookies: they only offer very limited space (4 kb), and because they are sent back and forth in plain, before sending back a malicious client content to the server, feel free to create an incredible form of cookie data. Can create from.

A session is a file on the server, which is identified by a unique ID that is forwarded between the client and the server so that the server can identify the client. The most popular way of sending session IDs is through a cookie mechanism, but it is also possible to pass session IDs through the URL (this is the reason why you often see that link in which the URL parameter is 'faxed'). It fixes two problems with the above mentioned cookies: the more important a file can be on the server, and the client can not access data other than its script.

Authentication is usually a cookie-based session; Once authenticated, a new session is created, and the user ID is stored in it, and when logging out, the session is cleared and a new session id is generated. Alternatively, you can store the user name and password in the session, and check them at each request.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -