What are the advantages and disadvantages of using Sessions over Cookies for storing data in PHP?

When deciding between using Sessions or Cookies for storing data in PHP, Sessions offer more security as the data is stored on the server side rather than on the client side like Cookies. Sessions also allow for larger amounts of data to be stored compared to Cookies. However, Sessions require server resources to store the data and may impact performance if not managed properly.

// Start a session
session_start();

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

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

// Destroy the session
session_destroy();