What are the advantages and disadvantages of using session variables over manually setting cookies in PHP?

When deciding between using session variables or manually setting cookies in PHP, session variables are typically easier to use and more secure as they are stored on the server side. However, session variables may consume more server resources compared to cookies, which are stored on the client side. Additionally, session variables are only available for the duration of a user's session, while cookies can have a longer lifespan.

// Using session variables
session_start();
$_SESSION['username'] = 'example_user';

// Manually setting cookies
setcookie('username', 'example_user', time() + 3600, '/');