How can PHP sessions and cookies be properly configured for compatibility across different PHP versions?

When configuring PHP sessions and cookies for compatibility across different PHP versions, it is important to ensure that the session settings are consistent and that cookies are properly set with the correct parameters. One way to achieve this is by setting the session cookie parameters explicitly and ensuring that the session configuration is compatible with various PHP versions.

// Set session cookie parameters
session_set_cookie_params(0, '/', '.example.com', false, true);

// Start session
session_start();