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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测