What are the potential security risks of not regenerating session IDs frequently in PHP applications?

Not regenerating session IDs frequently in PHP applications can increase the risk of session hijacking and session fixation attacks. Regenerating session IDs frequently helps to prevent an attacker from being able to predict or capture a valid session ID and gain unauthorized access to a user's session.

// Regenerate session ID every 30 minutes
if (isset($_SESSION['last_regenerated']) && time() - $_SESSION['last_regenerated'] > 1800) {
    session_regenerate_id(true);
    $_SESSION['last_regenerated'] = time();
} elseif (!isset($_SESSION['last_regenerated'])) {
    $_SESSION['last_regenerated'] = time();
}