Page 1 of 2

Day / Night graphic keeping current

Posted: Sat 27 Jan 2024 4:52 pm
by RayProudfoot
Many of us have added the Day / Night graphic to our websites over the years. It's a great way of seeing how much daylight the site has.

It also includes a marker for the current time but I have to manually refresh my page on Windows to show the current situation. On iOS it's a real pain as no refresh works.

Here's the code. Any chance of adding an instruction to my .htaccess file to keep it current? Thanks. :)

<td rowspan="5"><img id="img_sun"
src="http://cheadlehulmeweather.co.uk/heavens.php"
width="115" height="115"
alt="Day/Night/Twilight" title="Day/Night/Twilight" style="text-align:center" border="1"/></td>
<td rowspan="5">

Re: Day / Night graphic keeping current

Posted: Sat 27 Jan 2024 5:38 pm
by saratogaWX
The issue is caused by caching being enabled by your webserver for the .png image file created by heavens.php script.

For a simple test solution, try changing

src="http://cheadlehulmeweather.co.uk/heavens.php"

to

src="http://cheadlehulmeweather.co.uk/heavens.php?t=<?php echo time();?>"

to try and defeat the browser caching the image.

Otherwise, you'll need to change the cache configuration of the webserver for .png images to either set it to 1 hour or disable it.

Re: Day / Night graphic keeping current

Posted: Sat 27 Jan 2024 5:58 pm
by RayProudfoot
@saratogaWX, many thanks. I’ve updated my template and it will be executed in a few minutes.

It may take a little while to judge if it’s fixed. If further work is required I’ll come back as I’m unfamiliar with changing cache settings. Fingers crossed it works.

Re: Day / Night graphic keeping current

Posted: Sat 27 Jan 2024 6:07 pm
by RayProudfoot
I’ve checked on my iPad and Android phone as well as my windows laptop and it looks like your code has fixed it. :clap:

Many thanks! That has been bugging me for years! :D

Re: Day / Night graphic keeping current

Posted: Mon 29 Jan 2024 1:22 pm
by alexm2192
Unfortunately, there's no simple .htaccess tweak that can automatically refresh that external image source. The heavens.php script would need modifying to add metadata headers allowing the image to cache for only a few seconds.

However, a workaround for self-refreshing the image would be to wrap it in some JavaScript. For example:

Code: Select all

<script>
  setInterval(function() {
    document.getElementById('img_sun').src = 'http://cheadlehulmeweather.co.uk/heavens.php?rand=' + Math.random();
  }, 10000); 
</script>
This would append a random query string to "trick" the image into refreshing every 10 seconds.

Not as seamless as having the PHP script handle expires headers but could save needing manual refreshes. Let me know if you give that a try or have any other questions! A contract template is a pre-written document that provides a standard format and outline for creating a contract.Stepping into the trucking industry as an owner-operator comes with several decisions, one of the most significant being the choice of a comprehensive Owner Operator Lease Agreement template.

Re: Day / Night graphic keeping current

Posted: Mon 29 Jan 2024 1:51 pm
by RayProudfoot
@alexm2192, it looks like you didn’t see Saratoga’s suggestion which has solved it without the need to edit .htaccess. :)

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 11:41 am
by RayProudfoot
I've made a small change to my home page. I increased the size of the day / night graphic and it appeared okay.

But stupidly I uploaded the source code - sun_banner.php - replacing the original on the server without backing the original up first.

Now when I visit my homepage all I see is a placeholder, not the graphic.

I see the original name in the php is heavens and I haven't changed that. Just the name of the file.

If I type https://www.cheadlehulmeweather.co.uk/heavens.php into my browser it shows the graphic and the time appears correct.

But changing my home page code to point to heavens.php only shows the placeholder.

Could someone help please?

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 12:52 pm
by RayProudfoot
An update... I used Notepad++ to compare two php files. sun_button.php and sun_banner.php. The former shows when its address is entered into a browser. The latter doesn't.

I have eliminated all differences with the exception of the size. Surely that can be the reason sun_button with 75x75 shows and sun_banner with 75x150 doesn't. Later: Just chenged sun_banner.php to 75x75 and still it doesn't show.

Arrgghh!!! I'm sure this is related to dimensions but why?

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 12:54 pm
by Mapantz
Download a back-up from your cpanel.

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 1:28 pm
by RayProudfoot
Mapantz wrote: Mon 01 Jul 2024 12:54 pm Download a back-up from your cpanel.
I've looked in my cPanel and cannot see any option to restore files.

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 1:38 pm
by Mapantz
It should be under "Jet backup"

There should be daily backups for 30 days (for your whole site) and single file downloads are available for those 30 days.

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 1:44 pm
by RayProudfoot
I’ve downloaded the file but where does it reside? Looking at my files on the server there’s nothing shown as a download.

I’ve raised a ticket with my host.

Re: Day / Night graphic keeping current

Posted: Mon 01 Jul 2024 2:13 pm
by RayProudfoot
I was shown how to download my backup and have restored the original sun_banner.php and IndexT.html.

Image is back but I still don’t know what the problem was.

@Mapantz, thanks for that useful tip. :D

Re: Day / Night graphic keeping current

Posted: Tue 29 Oct 2024 10:05 am
by RayProudfoot
Before the clocks went back my Day / Night graphic was fine. But since it now appears offset so local noon appears to be at 11:00, not 12:00.

I don't understand how this could happen. I've looked at another site with it and it's fine there. Here's the link...

https://www.dmjsystems.co.uk/weatherbos/heavens.php

I can't read the source php file unfortunately. Here's mine https://www.cheadlehulmeweather.co.uk/on my home page.

Any help appreciated.

Re: Day / Night graphic keeping current

Posted: Tue 29 Oct 2024 11:11 am
by Mapantz
Opened both on my phone and they're identical Ray. Looks fine to me, so it might be a caching issue on the device you're using to look at it.