Is using cookies a viable solution for maintaining user sessions across multiple forums?

Using cookies is a viable solution for maintaining user sessions across multiple forums. By setting a unique session ID in a cookie when a user logs in, the session can be maintained as the user navigates between different forums. This allows the user to stay logged in and retain their session data across the various forums.

// Start the session
session_start();

// Generate a unique session ID
$session_id = uniqid();

// Set the session ID in a cookie
setcookie('session_id', $session_id, time() + 3600, '/');

// Store user data in the session
$_SESSION['user_id'] = $user_id;
$_SESSION['username'] = $username;

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