I am a front-end person, and I am exploring while working on a personal php project. I need to pass a user ID through a connection to display the data of the corresponding user. I am using mysql.
<a href="./index.php?ui=<?php echo $_SESSION[ 'username' ] ?>">
So I would like to ask whether id or username is generally used for this identification (association). If username is used for association, it can be obtained from the session.
Do you have to pass the ID to the front when using id association?
If username is unique, I personally recommend using username.
ID is usually self-increasing, so you can roughly estimate the real number of users of the website based on the ID.
For example: Many websites like to "show off" with the number of registered users, claiming to have how many registered users they have (more than 90% of them are bragging), so the ID must not be exposed.
Of course, if the ID you define is irregular, or you don’t need to hide this information externally, ID is perfect.
Id. What if the username becomes the same? So id must be set as the primary key
1. Usually id is used
2. Most of the id is not the primary key identifier, but the user's unique code
3. It seems that you are not very good at background language. Since you use session as a parameter, you can directly have background processing. Rather than using front-end processing. So there is no need to pass the ID
There are no hard requirements, but if you want to consider performance, just choose something short and simple.
For example:
Optimize performance and reduce matching processes such as numerical matching and string matching
This depends on your database design, but generally it is done with ID, username is not safe
We use sn, the user’s unique serial number
Understand the primary keys and foreign keys of the database