Hide registration and login buttons when a user logged in? [closed]

为君一笑 提交于 2019-12-13 09:56:16

问题


oK, since my original question didn't make sense to the majority, I will explain in details. I have a membership system I made through some tutorials based on codeigniter framework. on my main page I have 3 buttons containing login, register, forgot pass, respectively. when I test the login and enter my details as a user, I still can see the login button, which makes no sense because it should be hidden in case I logged in. The same thing for other features I mentioned above.

now I was trying some way like if($_SESSION['user'] == "") { to achieve my goal, but without any success.

any idea how to do this correctly?

Thanks


回答1:


<div id='nav'> 
<?php

if(is_logged_in())
{
    if(is_admin())
    {
        echo anchor('admin','Admin Dashboard');
    }

    echo anchor('user/logout','Logout');
    echo anchor('users/profile','Profile' . '&nbsp;[' . $_SESSION['user_name'] . ']');

}
else
{
    echo anchor('user/login','Login');
    echo anchor('user/signup','Signup');                        
}

echo '&nbsp;' . anchor(base_url(),'Home');
?>

</div>



回答2:


If you use sessions for being logged in

if( !isset($_SESSION) ){
    //echo links
}

make sure to unset() all your $_SESSION vars on logout




回答3:


I don't understand the question, because if you wrote the login system or can know when a user is logged in programmatically... there really should be no question. You can either load different views from the controller based on this "logged in" variable, or pass the variable to your view that is basically $displayLogin... if that is true, display the login information, if not, don't.

Would need to know more about your setup to provide more useful information obviously.



来源:https://stackoverflow.com/questions/9585996/hide-registration-and-login-buttons-when-a-user-logged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!