What are the advantages and disadvantages of cookies compared to sessions?

Can someone give me some good reading material on what is best in different cases?

I assume that when you have a small website with a small number of users, you can go to sessions, as they are stored on the server. But is it better for more users to go with cookies? And how do they both benefit in safety?

+3
source share
3 answers

Session management is divided into two methodologies: server and client. Using cookies establishes trust on the client side as well as part of managing the physical state of your application. Not all browsers support cookies, and users are able to either disable cookies based on their discretion. This creates a unique road block for many developers, since they cannot completely depend on the client system for them to actively accept cookies. Customers can kill active cookies at any time. The potential use of cookies is that it is managed by the client and can live in the client system, used to track visits to your site and other data that must be stored for long periods of time.

- . , . - , , - . - , -, , . , , , , .

+6

cookie ( ).

:

  • HTTP-
  • ,
  • , ( , , SSL)
  • .

.

?

, , cookie... .

+3

, , . - , , . , cookie . cookie , .

. , cookie . ( , ) - , . . . . . , .

. . cookie. , .

Edit: so I ran over my apache server and monitored RAM and processor activity. (No significant results). I also checked the time it took the server to set and cancel 1000 variables (containing a string of 30 characters) in sessions and in cookies. Carried out all tests a couple of times and took avg. result. Here are the results.

COOKIES
  Set: 0.001863 seconds.
  Unset: 0.004932 seconds.

SESSIONS:
  Set: 0.000494 seconds. (very consistent results)
  Unset: 0.000502 seconds. (Again very consistent)

Thus, sessions are much faster and more consistent. If you can use sessions. I would definitely go to the sessions.

+2
source

All Articles