What are the potential pitfalls of using sessions for user authentication in PHP?

One potential pitfall of using sessions for user authentication in PHP is the risk of session hijacking if the session ID is not properly secured. To mitigate this risk, it is important to use HTTPS to encrypt the session data during transmission and regenerate the session ID after a successful login to prevent session fixation attacks.

// Enable secure session cookie
ini_set('session.cookie_secure', 1);

// Regenerate session ID after successful login
session_regenerate_id(true);