What are some best practices for securing MySQL login systems in PHP, especially in terms of password hashing and session management?

Issue: Securing MySQL login systems in PHP involves properly hashing passwords and managing sessions to prevent unauthorized access. Code snippet:

// Hashing passwords using bcrypt
$password = 'password123';
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Verifying hashed passwords
if (password_verify($password, $hashed_password)) {
    // Password is correct
} else {
    // Password is incorrect
}

// Starting a secure session
session_start([
    'cookie_lifetime' => 86400, // Session cookie lasts for 24 hours
    'cookie_secure' => true, // Only send cookie over HTTPS
    'cookie_httponly' => true, // Prevent JavaScript access to session cookie
]);