简体   繁体   English

检查用户是否登录模板

[英]Checking if user is logged in the templates

Let's say I do something like this: 假设我做了这样的事情:

if (IsUserLoggedIn()) {
    echo $twig->render('home.html');
} else {
    echo $twig->render('login.html');
}

function isuserloggedin()
{
    return isset($_SESSION['userId']);
}

Is it a security issue not checking in the template... Or should it per-bases be fine? 不检入模板是否存在安全性问题?还是应该按基准使用?

Template: 模板:

Yo, you're logged in here, some details that only logged in should be able to see..

What I am asking is it essential to use some kind of conditional if statement in the Twig template to make sure again the user is logged in? 我要问的是,在Twig模板中使用某种条件性if语句来确保用户再次登录是必不可少的吗?

Cheers. 干杯。

This is perfectly fine logic. 这是非常好的逻辑。

Depending on how granular your user permissions are (for example, if you have regular user, power user and administrator), you can pass that permission level into the Twig template and display sections of the page based on those variables. 根据用户权限的细化程度(例如,如果您有普通用户,超级用户和管理员),可以将该权限级别传递到Twig模板中,并根据这些变量显示页面的各个部分。

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

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