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.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化