php 会话保存在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5593359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
where does session save?
提问by Moein Hosseini
I would like to know where PHP session data is saved; is it in client browser? or on the server?
我想知道PHP会话数据保存在哪里;是在客户端浏览器中吗?还是在服务器上?
When I disable cookies in my browser setting, PHP can't save session data, but in php.ini
, I can change the session save path.
当我在浏览器设置中禁用 cookie 时,PHP 无法保存会话数据,但在 中php.ini
,我可以更改会话保存路径。
Is session data stored on the server or client browser?
会话数据是存储在服务器还是客户端浏览器上?
回答by Pekka
The session datathat you read and write using $_SESSION
is stored on server side, usually in text files in a temporary directory. They can not be accessed from outside.
您使用的会话数据$_SESSION
存储在服务器端,通常存储在临时目录中的文本文件中。它们无法从外部访问。
The thing connecting a session to a client browser is the session ID, which is usually stored in a cookie (see the comments for exceptions to that rule). This ID is, and should be, the only thing about your session that is stored on client side.
将会话连接到客户端浏览器的是会话ID,它通常存储在 cookie 中(有关该规则的例外情况,请参阅注释)。此 ID 是并且应该是存储在客户端的有关会话的唯一信息。
If you delete the cookie in the browser, the connection to that session is lost, even if the file on the server continues to exist for some time.
如果您在浏览器中删除 cookie,则与该会话的连接将丢失,即使服务器上的文件继续存在一段时间。
The session.save_path
variable influences the location on the serverwhere the session data is stored. If you are not the server's administrator, it is usually not necessary to change it.
该session.save_path
变量影响会话数据在服务器上的存储位置。如果您不是服务器的管理员,通常不需要更改它。
回答by deceze
It's both! A session saves the actual session information on the server, but gives an identification cookie to the client to know which session belongs to which client. The information in the cookie itself is worthless, but allows the server to identify the client and use the actual session information.
两者都有!一个会话将实际的会话信息保存在服务器上,但是给客户端一个标识cookie,以知道哪个会话属于哪个客户端。cookie 中的信息本身毫无价值,但允许服务器识别客户端并使用实际会话信息。
回答by Ben
Blockquote "Is session data stored on the server or client browser?"
Blockquote“会话数据存储在服务器还是客户端浏览器上?”
It makes me think of a valet parking system. The valet (server) keeps your car (session data), but he/she gives you a ticket (session id) to hang onto which proves that the car is yours when you need access to it. If you lose your ticket (by deleting your cache, or closing the browser), your car (session data) is as good as gone since you can't prove it's your car anymore.
这让我想到了代客泊车系统。代客(服务器)保留您的汽车(会话数据),但他/她会给您一张票(会话 ID)以供您在需要访问时证明汽车是您的。如果您丢失了车票(通过删除缓存或关闭浏览器),您的汽车(会话数据)就如同消失了一样,因为您无法再证明它是您的汽车。
Okay, it's just an analogy...and breaks down quickly. E.g. you don't actually own your session information like you do your car. And you don't get to drive it away.
好吧,这只是一个类比……而且很快就会崩溃。例如,您实际上并不像拥有汽车那样拥有会话信息。你不能把它赶走。
回答by Nick Weaver
Both, the session in the client(browser) is saved as a cookie. This cookie references a session which also resides on the server.
两者都将客户端(浏览器)中的会话保存为 cookie。这个 cookie 引用了一个也驻留在服务器上的会话。
回答by Nick Weaver
It is stored on the server side to maintain security; but additional cookies could be also stored on the client side.
存储在服务器端,维护安全;但额外的 cookie 也可以存储在客户端。