Session ID 是在服务器端还是客户端生成的?
此网页 http://www.w3schools.com/ASP/prop_sessionid.asp 声明会话 ID 是在服务器端生成的。
如果是这种情况,那么服务器如何知道它在第二个请求响应周期仍然是同一个客户端?
SessionId 肯定会在客户端生成,以便客户端确保将相同的值传递给服务器吗?
This web page http://www.w3schools.com/ASP/prop_sessionid.asp states that a session ID is generated on the ServerSide.
If this is the case, then how does a server know it's still the same client on the 2nd request response cycle?
Surely the SessionId would be generated on the ClientSide so that the client would be sure of passing the same value to the server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
SessionID 在服务器端生成,但存储在客户端的 Cookie 中。 然后,每次客户端向服务器发出请求时,SessionID 都会用于验证客户端的现有会话。
The SessionID is generated Server Side, but is stored on the Client within a Cookie. Then everytime the client makes a request to the server the SessionID is used to authenticate the existing session for the client.
会话ID通常在服务器上生成。 然后将其作为 HTTP 标头中的 cookie 或将其包含在 HTML 中发送到客户端,即链接变为 href=my.html?sessionid=1234。
然后,客户端的下一个请求将在 cookie 或请求的 GET 部分中包含会话 ID。
The session ID is normally generated on the server. It's then sent to the client, either as a cookie in the HTTP headers, or by including it in the HTML, i.e. the links become href=my.html?sessionid=1234.
The client's next request will then contain the session Id, either in the cookie or the GET part of the request.
如果不存在,服务器将生成一个会话 ID。 但是一旦生成,客户端就可以将该 ID 传递回服务器。 如果客户端修改该 id,您可能会从服务器收到错误,并生成一个新的 id。
The server will generate a session id if none exists. But once it has been generated, the client can pass that id back to the server. If the client modifies that id, you would likely get an error from the server, and a new id generated.
ID是在服务器上生成的。 然后,客户端将其存储在服务器在后续请求中获取的会话 cookie 中。
如果服务器在无 cookie 模式下运行,则会话密钥将成为 URL 的一部分,服务器从那里解析它。
添加: ...如果服务器期望使用会话 cookie 但客户端禁用了 cookie,那么从服务器的角度来看,所有请求都是新会话,因为它无法判断这是同一用户。
The ID is generated on the server. The client then stores this in a session cookie that the server picks up on subsequent request.
If the server is running in cookie-less mode, then the session key becomes part of the URL and the server parses it from there.
ADDED: ...and if the server is expecting to use a session cookie but the client has cookies disabled, then from the perspective of the server, all requests are new sessions as it cannot tell that this is the same user.