Minor improvements.
- I updated the design a bit
- Added java script for automatic date/time updating
- Improved the API from PHP a bit
The java script
I just take the h1 and h2 tags and set their inner text every 1000 ms (1s) to a date.
Time was easy because we just use new Date().toLocaleTimeStrin() for the date i hade to get a bit more creative ${("0" + dt.getDay()).slice(-2)}.${("0" + (dt.getMonth() + 1)).slice()}.${dt.getFullYear()} ${weekdays[dt.getDay()]} / ${months[dt.getMonth()]} All this is there to have leading zeros that only appear when the second digit isn’t used (0-9). Also i convert months and days with help of arrays to short strings that are getting placed at the end. I personally need number & name because i really can’t memorize the names for the months.
The PHP
The PHP code is now also caching the image from the Nasa API so that clients don’t have to call any other servers. I also made the php script read from the API key file, trim spaces and other characters that are there for some reason and than use it. Of course i also added the .htaccess file to block access to the API_KEY.txt
Furthermore i added headers to stop clients from caching so that when a new image from Nasa replaces the old one the clients get the new image displayed. May be not the best solution but it works!
Another thing I would like to add is that I made it so that when a image from the API is requested with special copyright it gets displayed in the footer. If the API doesn’t give an copyright notice the PHP script just default to Nasa.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.