How can session_set_cookie_params be used to maintain sessions and cookies across multiple domains in PHP?

When working with sessions and cookies across multiple domains in PHP, it is important to set the cookie domain parameter to the parent domain to ensure that the session is maintained across all subdomains. This can be achieved using the session_set_cookie_params function in PHP by specifying the domain parameter as the parent domain.

<?php
$domain = '.example.com'; // Replace with your parent domain
session_set_cookie_params(0, '/', $domain);
session_start();
?>