douqiang6448 2019-03-26 16:43
浏览 51
已采纳

如何通过创建SESSION创建一个使用PHP,MYSQL和HTML的登录系统[关闭]

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

  • 写回答

1条回答 默认 最新

  • doufan1899 2019-03-26 17:17
    关注

    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 :

    <?php
       if($_SESSION['online']){ echo 'You are online';}
    ?>
    

    And to disconnect someone from the sessions

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?