2019-03-26 16:43


I need to create a login system, where once logged in, depending on the user type, users will be able to access certain pages. I also need to ensure that these users are able to logout of their accounts. I will be using a phpmyadmin database to store the user data, and their user type.

I have attempted to create this, however my current code does not work at all. Despite the users having a record in phpmyadmin, and with a defined user type; I am unable to login using their details. Instead I am presented with an error message, stating that the account cannot be located. I understand that the best way resolve this issue, is to implement a SESSION into my code, so users are not only able to login but their user type is remembered throughout their session.

How can I implement a SESSION into my code? Does anyone have any advice? Also I'm new to slack- please let me know if you have any questions on the above. Thanks

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doufan1899 doufan1899 2年前

    For using SESSION stuff you need to start every page.php by:

    <?php session_start(); ?>

    After what, you can cast some $_SESSION variable like:

    $_SESSION['name'] = 'Alex';
    $_SESSION['online'] = TRUE;

    So you could use it :

       if($_SESSION['online']){ echo 'You are online';}

    And to disconnect someone from the sessions

    <?php session_start();
      $_SESSION = array(); //to delete every $_SESSION variables

    For the rest of your ask, it's way too long to explain it there. You should follow some tutorial.

    点赞 评论 复制链接分享