为所有用户创建 PHP 会话还是只为想要登录的用户创建 PHP 会话? [英] Create PHP session for all users or only ones who want to log in?

查看:51
本文介绍了为所有用户创建 PHP 会话还是只为想要登录的用户创建 PHP 会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的 CMS 为访问该站点的每个用户创建了一个 PHP 会话.我正在考虑只为想要登录的用户创建一个会话.我在这里遇到的问题是登录用户的一些 UI 元素在所有页面上,因此在每个页面请求中,系统必须检查用户是否是已登录,这意味着我没有其他选项可以在每个页面请求上启动会话?还是我错了?即使不想登录,为每个用户创建会话是否正常?

At the moment my CMS creates a PHP session for every user who visits the site. I'm thinking about only creating a session for users who want to log in. The problem I have here is that some UI elements for logged in users are on all pages, so on every page request the system has to check if the user is logged in, which means I have no other option to start a session on every page request? Or am I wrong? Is it normal practise to create a session for every user, even if dose not want to log in?

简而言之,我想知道 A. 在我的用例中是否有一个选项可以只为想要登录的用户创建一个 PHP 会话,B. 如果认为为每个用户创建一个会话是不好的做法,不管他想不想登录.如果不是这样,我可以保持原样......

Short, I'd like to know if A. there is an option in my use case to only create a PHP session for users who want to log in and B. if it consider bad practise creating a session for every user, regardless if he wants to log in or not. If this isn't the case, I can leave things as they are really ...

推荐答案

您别无选择.您无法知道用户是否在没有会话的情况下登录(或未登录).

You have no (real) choice. You can not know, that a user is logged in (or not) without a session.

这篇关于为所有用户创建 PHP 会话还是只为想要登录的用户创建 PHP 会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆