How do I authenticate a user in PHP / MySQL?

前端 未结 7 1529
春和景丽
春和景丽 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:49

    You could use a select statement to retreive from MySQL the password for the specified username. If you have an empty result set, then you do not have the username in the table.

    If you need the user to be authenticated in more than one php page, then one choice whould be using sessions (http://www.php.net/manual/en/function.session-start.php).

    Also, I think you should think about security, i.e. preventing SQL injection:

    $variable = mysql_real_escape_string($_POST['variable'])
    

    and avoiding to "die" (treating errors and returning user-friendly messages from the script).

提交回复
热议问题