I am a little confused with the use of sessions in PHP, esp. with maintaining user sessions after login. So to maintain sessions, one of the methods that we can use is using the session\_start() in PHP. 

Now session\_start() generates a unique sessionID and sends a cookie to the browser with this id, if I am correct (as I read from several resources).

Now lets take a simple user login use case where I need to maintain sessions. So typically and a very simple scenario, user logs enters his username and password in the respective fields on the form. Then user presses the submit button. 

The POST values get sent to the PHP script, say login.php, that handles sessions. Inside login.php I check for $\_POST['username'] and $\_POST['password'] to see if it matches the values present in the db. Let's assume that the values match. 

So a new session should be created now, right? Why do we include session\_start() in the beginning of login.php then? 

Secondly, so after the session is started and a sessionID is created it is sent in a cookie to the browser and is also recorded in the $\_SESSIONS global variable. So now the thing is where in all this did we bind this session with this particular user ? I understand that since the cookie will be sent by the user with every request, and since the server has the same sessionID, as in the cookie, maintained at its end as well, the server would know that the request is coming from the same user. But then we are not recording this sessionID explicitly anywhere (in the db etc.) for this user. So if i need all the other details about this user, how would i get it ? So how exactly is the sessionID connected with a particular user's details stored in the db ?

So to give an example, let's assume that in the above case the user we discussed was say USER A. For a second user, say USER B also all the above would hold true. So now the server will definitely be able to distinguish between requests from both these users because of the 2 different sessionIDs that will be sent by these users in the cookies with their requests. But on the server side, how will USER A's request be linked with USER A's details in the db and how will USER B's request be linked with USER B's details in the db ?