What are the potential security risks of including usernames and passwords in URLs for file access in PHP?

Including usernames and passwords in URLs for file access in PHP can pose a security risk as this information can be easily visible in browser history, server logs, and can be intercepted by malicious actors. To mitigate this risk, it is recommended to use session tokens or other forms of authentication instead of passing sensitive information in URLs.

// Implementing authentication using session tokens instead of passing usernames and passwords in URLs
session_start();

if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
    header('Location: login.php');
    exit();
}

// Your file access code goes here