How can I prevent Siteground's website caching from affecting PHP's day and time detection?

I have a PHP script that presents website visitors with different instructions depending on the day of the week and the time of day. My website is hosted on Siteground. They have a tremendous caching feature that??�s meant to speed up a website. However, because the page that uses the PHP script gets cached it cannot accurately detect day and time. Is there any way I can solve this by adding something to my PHP script? Mind you I only know how to write procedural PHP. This particular page is essential for my business therefore to maximize search engine crawling budget I use PHP??�s function

header(???Cache-Control: max-age=315360000)

The correct time zone is set with PHP??�s function

date_default_timezone_set('America/Anchorage');

Thank you for reading.

Answer

Solution:

According to the Siteground's documentation you need to set the Cache-Control header to private. But as your PHP files have already been cached you should set this header and then purge the cache to reload them or you can try modifying the web server configuration to do this for you.

You can disable the Siteground PHP caching by adding the following to your web server configuration (I assume Apache, .htaccess file in your public_html directory):

<If "%{REQUEST_URI} =~ /yourfilename.php$/">
  <IfModule mod_headers.c>
    Header set Cache-Control "private"
  </IfModule>
</If>

If you have different page counting, all examples can be found here: Siteground: How to disable the caching

Source