What are the best practices for handling user authentication and identification in PHP when interacting with Majordomo?

When interacting with Majordomo in PHP, it is important to handle user authentication and identification securely to protect sensitive information. One best practice is to use sessions to store user credentials and check them on each request to ensure the user is authenticated before accessing protected resources.

session_start();

if (isset($_SESSION['user_id'])) {
    // User is authenticated, proceed with the request
} else {
    // Redirect to login page or display an error message
    header("Location: login.php");
    exit();
}