What are some potential security risks of using a random string and username as cookies for user authentication in PHP?

Using a random string and username as cookies for user authentication in PHP can pose security risks such as cookie tampering and session hijacking. To mitigate these risks, it is recommended to use a combination of a secure random token and a unique identifier for the user. This way, even if the random token is compromised, the unique identifier can still be used to verify the user's identity.

// Generate a random token
$random_token = bin2hex(random_bytes(16));

// Set the random token and username as cookies
setcookie('auth_token', $random_token, time() + 3600, '/');
setcookie('username', $username, time() + 3600, '/');