What potential issues can arise from relying on the User Agent for login and session management in PHP applications?

Issue: Relying on the User Agent for login and session management in PHP applications can lead to security vulnerabilities as the User Agent can be easily spoofed or manipulated by attackers.

// Use session cookies for login and session management instead of relying on User Agent

// Start a session
session_start();

// Set session variables
$_SESSION['user_id'] = $user_id;

// Validate session on each page load
if (!isset($_SESSION['user_id'])) {
    // Redirect to login page
    header("Location: login.php");
    exit();
}