What are the potential pitfalls of storing data in cookies instead of using sessions in PHP?

Storing data in cookies instead of using sessions in PHP can lead to security vulnerabilities as cookies are stored on the client-side and can be easily manipulated. To solve this issue, it is recommended to use sessions in PHP for storing sensitive data.

// Start a session
session_start();

// Store data in session variable
$_SESSION['username'] = 'example_username';

// Retrieve data from session variable
$username = $_SESSION['username'];