What potential issues can arise when storing data in PHP sessions and how can they be avoided?

One potential issue when storing data in PHP sessions is the risk of session hijacking or session fixation attacks. To avoid this, it's important to regenerate the session ID after a user logs in, logs out, or performs any action that changes their authentication status.

// Regenerate session ID to prevent session fixation attacks
session_regenerate_id(true);