UserCake / PHP - isUserLoggedIn不起作用,给出空白页面

时间:2015-11-27 21:52:35

标签: php login usercake

我试图检查用户当前是否已登录。 如果用户已登录,我想在菜单中回显正确的<li>

我尝试在页面顶部执行此操作:

<?php

// Report all PHP errors (see changelog)
error_reporting(E_ALL); 

require_once ('models/config.php');
//$username = $loggedInUser->username; 

if ($isUserLoggedIn()) {
    $r1 = $loggedInUser->username;
    $r2 = "Logout";
} else {
    $r1 = "Login";
    $r2 = "Register";
}
?>

以及<li>代码:

<li><a class="short" href="About" style="display: block;"><?php echo $r1 ?></a></li>
    <li><a class="short" href="About" style="display: block;"><?php echo $r2 ?></a></li>

1 个答案:

答案 0 :(得分:0)

您使用错误的代码进行检查用户是否已登录,它是: isUserLoggedIn

试试这个:

<?php

// Report all PHP errors (see changelog)
error_reporting(E_ALL); 

require_once ('models/config.php');
//$username = $loggedInUser->username; 

if (isUserLoggedIn()) {
    $r1 = $loggedInUser->username;
    $r2 = "Logout";
} else {
    $r1 = "Login";
    $r2 = "Register";
}
?>