官术网_书友最值得收藏!

Keeping sessions in HTTP

HTTP is a stateless client-server protocol, where a client makes a request and the server responds with the data. The next request that comes is treated as an entirely new request, unrelated to the previous one. The design of HTTP requests is such that they are all independent of each other. When you add an item to your shopping cart while shopping online, the application needs a mechanism to tie the items to your account. Each application may use a different way to identify each session.

The most widely used technique to track sessions is through a session ID (identifier) set by the server. As soon as a user authenticates with a valid username and password, a unique random session ID is assigned to that user. On each request sent by the client, the unique session ID is included to tie the request to the authenticated user. The ID could be shared using the GET or POST method. When using the GET method, the session ID would become a part of the URL; when using the POST method, the ID is shared in the body of the HTTP message. The server maintains a table mapping usernames to the assigned session ID. The biggest advantage of assigning a session ID is that even though HTTP is stateless, the user is not required to authenticate every request; the browser would present the session ID and the server would accept it.

Session ID also has a drawback: anyone who gains access to the session ID could impersonate the user without requiring a username and password. Furthermore, the strength of the session ID depends on the degree of randomness used to generate it, which could help defeat brute force attacks.

主站蜘蛛池模板: 大渡口区| 东光县| 永吉县| 西贡区| 毕节市| 泸溪县| 永川市| 山东省| 鹤峰县| 安庆市| 镇安县| 凤阳县| 周口市| 隆尧县| 博白县| 台中市| 双流县| 锦州市| 青神县| 内乡县| 舟曲县| 嘉祥县| 新竹县| 益阳市| 潞城市| 浙江省| 深圳市| 普宁市| 德庆县| 堆龙德庆县| 临颍县| 兰考县| 嘉禾县| 临海市| 年辖:市辖区| 延川县| 北碚区| 依安县| 洪洞县| 特克斯县| 玉林市|