What are the potential pitfalls of using $_SERVER['PHP_AUTH_USER'] for user authentication in PHP?

Using $_SERVER['PHP_AUTH_USER'] for user authentication in PHP can be insecure as it relies on basic authentication which sends credentials in plaintext. It is recommended to use more secure methods such as sessions or tokens for authentication.

// Example of using sessions for user authentication
session_start();

if (isset($_SESSION['user'])) {
    // User is authenticated
} else {
    // Redirect to login page
    header('Location: login.php');
    exit();
}