Adding User Id to Session
Suppose that in addition to the authorization mark, we would
also like to write his id to the session.
In this case, we can get it using the
function mysqli_insert_id. This function
gets the id of the last record inserted
in this script, which is exactly
what we need.
Let's implement it:
<?php
if (!empty($_POST['login']) and !empty($_POST['password'])) {
$login = $_POST['login'];
$password = $_POST['password'];
$query = "INSERT INTO users SET login='$login', password='$password'";
mysqli_query($link, $query);
$_SESSION['auth'] = true;
$id = mysqli_insert_id($link);
$_SESSION['id'] = $id; // writing id to the session
}
?>
During registration, also write the user's id
to the session.