Training, Open Source computer languages

PerlPythonMySQLTclRubyC & C++LuaJavaTomcatPHPhttpdLinux

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Morning image, afternoon image

"I want to show one picture on my website in the morning and a different one in the afternoon".

Doesn't that sound like it's a simple request ... yet - as ever with computing - it raises a whole lot more questions, with a raft of possible answers.

* Do you want the time from the server? Where's your server? One of ours is in California, and the other is in Germany! Or would you prefer the time to reflect where your main customer base is (the UK), or where people are browsing from?

* Do you want to change your HTML every 12 hours to pull in the new image, or to have a URL for the image that changes? Or do you want to run a timed job on the server to switch the image for you? Does it matter??

If you're looking for server or main customer base time to be reflected in the image, the easiest way is to use PHP for the image generation. Here's code to choose between two images based on the server's hour:

$hour = date("G");
$image = "psh1";
if ($hour > 12) $image = "chsid";


and you would write something like:
<img src=/whimg/<?= $image ?>.jpg>
actual HTML.

See a worked example with source code.

Variations:

1. Changing to a different (fixed) timezone is quite easy - use either the date or gmdate functions from PHP and add or subtract an appropriate offset.

2. Timing by browser is a little more tricky. I would identify the country using Maxmind and then work with a table of time zones such as those here and here. Even then, you'll have daylight saving to take into account ...

3. If you prefer to keep your HTML fixed, you can use PHP to generate your image - example (to display a random image) here on our forum.

4. A further variation if you want to change the image but use static images and pages is to use a regular timed job (crontab) to change the file on the server at the correct times.
(written 2005-12-26 13:54:05)

 
Associated topics are indexed under
H112 - PHP - Further Web Page and Network Handling

Back to
Christmas is for everyone
Previous and next
or
Horse's mouth home
Forward to
The world didn't stop for Christmas
Some other Articles
The relevance of the hairy woodpecker
Is training seasonal?
Repeating tasks with crontab
The world didn't stop for Christmas
Morning image, afternoon image
Christmas is for everyone
Christmas Party
rich and famous
A company we can work with
Daily Image Santafied
1892 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho