$_Session “complication” on login and logout php

后端 未结 1 1395
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 22:45

I\'m doing a database project for university and I\'m strugling with a problem in here. I\'m trying to show \"log in\" when there\'s no session and \"log out\" when there is

相关标签:
1条回答
  • 2021-01-18 23:10

    when your login is success on login page.

    session_start();
    $_SESSION['user_logged_in'] = true;
    

    in your logout page

    session_start();
    unset($_SESSION['user_logged_in']);   
    session_destroy();
    

    in your home page

    <?php 
       session_start();
       if(isset($_SESSION['user_logged_in'])) {
     ?>
       < a href='logout.php'>Logout</a>
    <?php  
       }
    else {
    ?>
        < a href='login.php'>Login</a>
    <?php 
      }
     ?> 
    
    0 讨论(0)
提交回复
热议问题