Laravel如何管理会话?(How Laravel manages sessions?)

编程入门 行业动态 更新时间:2024-10-22 18:42:09
Laravel如何管理会话?(How Laravel manages sessions?)

关于Laravel如何管理会话,我需要一些帮助。 当我使用纯PHP进行编程时,我使用的是全局变量$ _SESSION。 这样,当我想检索有关用户的信息时,我通过$ _SESSION ['id']变量在数据库中找到用户。 我不明白Laravel如何使用它。 你能指导一些指南吗? 提前致谢。

I need some help regarding on how Laravel manages sessions. When I was programming with pure PHP, i was using the global variable $_SESSION. This way, when I wanted to retrieve information regarding an user, I was finding the user in the database by $_SESSION['id'] variable. I do not understand how Laravel works with this. Can you guide to some guides, please? Thanks in advance.

最满意答案

正如第一条评论所指出的那样,Laravel拥有自己的Session控制系统,可以通过使用Session Facade在应用程序的任何位置访问它。

要在会话中存储值,您可以

Session::put('key', 'value');

要检索值:

$value = Session::get('key');

As pointed in the first comment, Laravel has it's own Session controlling system, that can be accessed, at any point of your application, by using the Session facade.

To store a value in the session, you do

Session::put('key', 'value');

To retrieve the value:

$value = Session::get('key');

更多推荐

本文发布于:2023-08-01 10:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1358059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Laravel   manages   sessions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!