What are best practices for handling browser caching in PHP to prevent outdated content display?

When serving dynamic content in PHP, it's important to set proper caching headers to prevent outdated content from being displayed to users. One common approach is to set the "Cache-Control" header to specify how long the content should be cached by the browser. Additionally, using versioning in URLs or adding a unique query parameter for each new version of the content can also help bypass browser caching issues.

// Set caching headers to prevent outdated content display
$expires = 60 * 60 * 24 * 7; // 1 week
header("Cache-Control: max-age=$expires, must-revalidate");
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');

// Output your dynamic content here
echo 'Hello, world!';