How do I authenticate a user in PHP / MySQL?

前端 未结 7 1505
春和景丽
春和景丽 2020-12-08 09:26

So recently I learned how to properly add a username and password to a database. My database is usersys, and the table storing user information is called userdb. The table h

相关标签:
7条回答
  • 2020-12-08 09:56

    You can use sessions. Sessions are global variables that when set, stay with the user while he is browsing through the site.

    Since you are learning PHP, try out this tutorial on the official website.

    But what you would do in theory is when the username and password match, you set a session variable

    $_SESSION["auth"] = true;
    $_SESSION["user_id"] = $row["user_id"];
    

    And then do a check to see if the user is authenticated.

    0 讨论(0)
提交回复
热议问题