What best practices should be followed when setting session cookies for multiple websites under the same domain?

When setting session cookies for multiple websites under the same domain, it is important to set a unique session name for each website to prevent conflicts. This can be achieved by customizing the session name based on the website's domain or subdomain. Additionally, it is recommended to set the session cookie path to the root directory of each website to ensure the session is accessible across all pages within the website.

<?php
// Set a unique session name for each website
$website_domain = $_SERVER['HTTP_HOST'];
session_name('custom_session_' . str_replace('.', '_', $website_domain));

// Set the session cookie path to the root directory of each website
session_set_cookie_params(0, '/', $website_domain);

// Start the session
session_start();
?>