What are the potential pitfalls of storing login credentials in cookies in PHP?

Storing login credentials in cookies in PHP can pose a security risk as cookies are easily accessible and can be tampered with. To mitigate this risk, it is recommended to store a unique session identifier in the cookie instead of the actual login credentials. This session identifier can then be used to retrieve the user's information securely from the server.

// Set a unique session identifier in the cookie
$session_id = uniqid();
setcookie('session_id', $session_id, time() + 3600, '/');

// Store the session identifier in the server-side session storage
$_SESSION['user_id'] = $user_id;
$_SESSION['session_id'] = $session_id;