Analyze the differences between session and cookie

Source: Internet
Author: User
Security comparison: Sessions are stored on the server, and the client does not know the information. cookies are stored on the client, and the server can know the information. Cookie is not very secure. others can analyze the cookies stored locally and perform cookie spoofing. considering the security, session should be used for security comparison: Session is saved on the server side, the client does not know the information. the cookie is saved on the client, and the server can know the information. Cookie is not very secure. others can analyze the local cookies and perform cookie spoofing. session should be used for security.
Comparison from the access method: objects are saved in the Session, and strings are saved in the cookie.
Compare whether to differentiate paths: Sessions cannot differentiate paths. when a user accesses a website, all sessions can be accessed anywhere. If path parameters are set in the cookie, the cookies in different paths of the same website cannot access each other.
Compare the working methods: the Session must use cookies to work normally. If the client completely disables cookies, the session will become invalid.
In terms of server performance, the Session will be stored on the server for a certain period of time. When the number of accesses increases, the performance of your server will be relatively occupied. to reduce the server performance, cookies should be used.
The set time should be used with cookie: session_set_cookie_params = "";
Setcookie (name, value, time endpoint (timestamp), Path, scope );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.