简体   繁体   English

HTTP 会话究竟是如何工作的,在什么情况下它会过期(在 Laravel 中)?

[英]How does an HTTP session exactly work and in what cases does it expire (in Laravel)?

I'm creating a Laravel application and I'm trying to grasp the concept of the HTTP session .我正在创建一个 Laravel 应用程序,并试图掌握HTTP session概念 I noticed that I don't really understand it on a fundamental level (eg what exactly happens ).我注意到我在基本层面上并没有真正理解它(例如究竟发生了什么)。

On the internet there isn't much information available besides some basic stuff (getting and retrieving data, plus a few other common things).在互联网上,除了一些基本的东西(获取和检索数据,以及一些其他常见的东西)之外,没有太多可用的信息。

I want to better understand it, so it'd be extremely helpful is someone could clarify the following things for me:我想更好地理解它,因此如果有人可以为我澄清以下事项,那将非常有帮助:

  1. What is a session exactly?什么会话? What is meant with the driver?司机是什么意思? (Laravel offers: "file", "cookie", "database", "apc", "memcached", "redis", "dynamodb", "array".) What happens to it when I choos e file vs cookie ? (Laravel 提供:“file”、“cookie”、“database”、“apc”、“memcached”、“redis”、“dynamodb”、“array”。)当我选择e file vs cookie时会发生什么?
  2. What does it mean when a session expires ?会话过期是什么意思 Is that when a user navigates away, or is it only for a specific time in the browser?那是当用户导航离开时,还是仅在浏览器中的特定时间? Eg if I redirect the user the some OAuth during onboarding, does that mean that the session expires or not?例如,如果我在入职期间将用户重定向到某个 OAuth,这是否意味着会话是否过期?

Many thanks in advance!提前谢谢了!

As you can see, session is dependent on the driver you choose, and at the same time you can select the timeout as well in config\\session.php .如您所见, session取决于您选择的driver ,同时您也可以在config\\session.php选择超时。

In case of Cookie , the session will expire in two cases:Cookie情况下,会话将在两种情况下过期:

  1. Once the cookie has expired/deleted.一旦 cookie 过期/删除。
  2. Or (current_time - cookie_creation_time) > session_timeout set in the session.php .或者(current_time - cookie_creation_time) > session_timeoutsession.php设置。

In all drivers, one thing is common: whenever you access the website, and a request is made to the server, it will add the last access time and calculate the session timeout from there.在所有驱动程序中,有一件事是共同的:每当您访问网站,并向服务器发出请求时,它会添加上次访问时间并从那里计算会话超时。

When the user navigates from the browser and the cookie is still there and it hasn't expired, the user will be identified and session will remain the same.当用户从浏览器导航并且 cookie 仍然存在并且它没有过期时,用户将被识别并且会话将保持不变。

I hope it's clearer... If not, let me know.我希望它更清楚......如果没有,请告诉我。 I will share some examples.我将分享一些例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM