What are the best practices for handling character encoding, such as UTF-8 without BOM, in PHP files to avoid session-related problems?

When handling character encoding in PHP files, it is important to use UTF-8 without BOM to avoid session-related problems. To achieve this, ensure that your PHP files are saved with UTF-8 encoding without the Byte Order Mark (BOM) at the beginning of the file. This can be done by configuring your text editor to save files in the correct encoding.

<?php
// Set UTF-8 encoding without BOM
header('Content-Type: text/html; charset=utf-8');
ob_start('ob_gzhandler');
session_start();
// Your PHP code here
?>