What role do cookies play in maintaining session information in PHP?

Cookies play a crucial role in maintaining session information in PHP by storing a unique session identifier on the client-side. This identifier is used to link the client's requests to the server's session data, allowing the server to maintain stateful information across multiple requests. By setting a session cookie with the session ID, PHP can identify and retrieve the corresponding session data for each user.

// Start a new session or resume the existing session
session_start();

// Set a session cookie with a unique session ID
setcookie(session_name(), session_id(), time() + 3600, '/');

// Access and store session data as needed
$_SESSION['username'] = 'example_user';