What are the potential security risks associated with using cookies in a PHP login system?

Potential security risks associated with using cookies in a PHP login system include session hijacking, where an attacker can steal a user's session cookie and impersonate them, and session fixation, where an attacker can set a user's session ID before they log in. To mitigate these risks, it's important to use secure cookies with the HttpOnly and Secure flags, as well as implement measures such as regenerating the session ID on login.

// Set secure and HttpOnly cookies for session management
session_set_cookie_params([
    'lifetime' => 0,
    'path' => '/',
    'domain' => 'example.com',
    'secure' => true,
    'httponly' => true
]);

// Start session
session_start();

// Regenerate session ID on login
session_regenerate_id(true);