首页 > 解决方案 > Changing the function of a button based on if a user is logged in

问题描述

I am trying to create an application page within a website and currently, I have a button that takes users to an application when clicked. However, I only want users who are logged in to be able to work on the application so is there any way that I can put a conditional on the button so that if the user is not logged in it first takes them to the login page before taking them to the application page.

标签: htmlauthentication

解决方案


So basically need to use sessions to check if user is already logged in or nor. You can't do it in HTML. If you are using backend language for example PHP, then you can do it in this way:

       <?php
        session_start();
        if(isset(SESSION_["user"]){
        //do task which you want to do if user is logged in
        }
else{
//do task when user is not logged in
}
    ?>
         

推荐阅读