What are the advantages and disadvantages of using cookies for session management in PHP?

Cookies can be used for session management in PHP by storing a session ID in a cookie. This allows for persistent sessions across multiple page loads without the need for server-side storage. However, cookies can be vulnerable to security risks such as session hijacking or XSS attacks if not implemented properly.

// Start a session and set a session ID in a cookie
session_start();
$session_id = session_id();
setcookie('session_id', $session_id, time() + 3600, '/', '', false, true);