In this fictitious example, we has users database with email and password. It uses an HTML form with inputs to retrieve the user login credentials.
When the user submits their login details, then the PHP code will receive the posted data. It compares the entered data against the user database.
If match found, then it sets the user login session. In this authentication code, it preserves the user id in a PHP session. The existence of this session will state user authentication status.
After authentication, the PHP $_SESSION super global variable will contain the user id. That is, the $_SESSION[“user_id”] is set to manage the logged-in session. It will remain until log out or quit from the browser. While logout, we unset all the session variables using PHP unset() function.