What are the potential risks and benefits of storing login data as sessions or cookies in PHP?

Storing login data as sessions in PHP is generally more secure than using cookies because sessions are stored on the server-side. However, sessions can be vulnerable to session hijacking if not implemented properly. Cookies, on the other hand, are stored on the client-side and can be manipulated by the user, posing a security risk. It's important to carefully consider the trade-offs between security and convenience when deciding whether to store login data as sessions or cookies in PHP.

// Storing login data as a session
session_start();
$_SESSION['username'] = 'example_user';

// Retrieving login data from session
session_start();
$username = $_SESSION['username'];