What are some best practices for handling password expiration checks in PHP applications to ensure security and user compliance?

When handling password expiration checks in PHP applications, it is important to enforce regular password changes to enhance security and ensure user compliance with password policies. One best practice is to set a maximum password age and prompt users to update their passwords when they expire.

// Check if user's password has expired and prompt for update
if ($user->password_last_updated < strtotime('-90 days')) {
    echo "Your password has expired. Please update it now.";
    // Redirect user to password reset page
    header("Location: reset_password.php");
    exit();
}