如何使用CodeIgniter管理会话和用户?

发布于 2024-12-29 10:53:57 字数 227 浏览 1 评论 0原文

我正在将我的网站迁移到 CodeIgniter 框架中。我以前从未使用过 MVC 框架,所以这是一大进步。

在我的旧网站中,每个页面的顶部都有 include("session_handler.php"); 。该脚本将检查会话变量、验证会话并将内容存储在数据库中。

有没有办法让这个脚本自动包含在每个页面中?我可以在配置中指定它吗? CI 是否有一种内部处理会话的方法优于我的方法?

I'm in the middle of moving my site into the CodeIgniter framework. I've never used a MVC framework before so this is a big step.

In my old site, each page would have include("session_handler.php"); at the top of each page. This script would check session variables, authenticate sessions and store stuff in the database.

Is there a way I can have this script automatically include in every page? Can I specify it in the config? Does CI maybe have an internal way of dealing with sessions that is superior to my method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2025-01-05 10:53:57

Code Igniter 有一个可以使用的 Session 类

它还具有自动加载功能

我认为这两件事应该满足您的要求...

如果您需要对会话进行额外的验证,您可以扩展核心会话类(如果您只是开始使用框架,这可能会要求太多),或者您可以创建您自己的库并在会话结束后立即自动加载它以运行一些附加代码..

Code Igniter has a Session class you can use.

It also has an autoload functionality.

Those two things should cover your requirements I think...

If you need additional validation to the session, you can either extend the core session class (which may be asking too much if you're only starting on the framework) or you can create your own library and auto-load it right after the session one to run some additional code..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文