存储或获取用户ID作为PHP会话变量[重复]

This question already has an answer here:

In a login system, we are using a table to store login details of students. Columns are : StudentID (int, Auto Increment, Primary Key) StudentName (Varchar, 50) and StudentPassword (Varchar, 16). When the Student logins, we are getting session variable : $_SESSION['Username']. Now, since we are using the StudentID as primary key, it is used to link other tables in the database, we need to store / Get the StudentID as session variable. How to get this extra column as server variable?

</div>

You usually do this at the point of login. Say we got a database row $row

     $_SESSION['user-id'] = $row['user_id'];