
The simplest ideas are often the best ... and the simple idea of having a picture that automatically changes from time to time on your web page helps keep your customer's interest up when he returns to your site. You're seeing a picture of our dog Gypsy to the right of this block of text, but I don't know exactly which one ...
On yesterday's
PHP course, I wrote an example that selects the picture that is displayed based on the number of minutes that have elapsed into the hour - you can run that page
[here] and you can see the source code
[here]. It's an easy step to change the "number of minutes" into a "number of hours" into the day, and produce a page that shows a different image depending on the time of day - a nighttime shot until 7 a.m., then a breakfast, followed by ... well, you'll be getting the idea.
A further request that your customers may make is for changed character sizes, backgrounds, etc - and if you provide a "service" you've a legal requirement in the UK to take all reasonable steps to ensure your service is accessible to the disabled, which means (on a web site) that you should provide this flexibility, not require your users to link via images which may not be accessible on browsers that read words for the blind, etc.
The same example code includes a simple example of using a form (or pseudo form) element to provide an input to the page, which sets a cookie and allows for a colour change to be requested and saved. In the case of the example, I have set a six hour timeout on the cookie so that it'll be reset for me for demonstration purposes by the following day ... you might choose to use a year or two.
Although both of the examples here are very short, simple, straightforward, I
have enhanced them slightly since yesterday's demonstration by adding in a couple of checks to ensure that a malicious user can't inject a request for a colour that we didn't offer, or something rather more nasty. Bear in mind that even with these simples of demonstrations, you need to have one eye open for the security of your web site if you're running code on it - especially code that has user inputs!
(written 2009-12-17)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H304 - PHP - DDA, Style and image handling [806] Check your user is human. Have him retype a word in a graphic - (2006-07-17)
[1506] Ongoing Image Copyright Issues, PHP and MySQL solutions - (2008-01-14)
[2031] Choosing from an image with an image map - (2009-02-08)
[2343] World Flags in your PHP pages - (2009-08-10)
[2715] Uploading an image, document or pdf via a browser (php) - (2010-04-10)
[2917] Upload Image, Store in database, redisplay in browser. PHP and MySQL - (2010-08-12)
[3747] An easy way to comply with the new cookie law if your site is well designed - (2012-06-02)
G996 - Well House Consultants - Newsletter Scripts [1001] .pdf files - upload via PHP, store in MySQL, retrieve - (2006-12-19)
[1066] Final, Finally and Finalize - three special words in Java - (2007-02-05)
[1123] mysqldump and mysqlrestore - (2007-03-30)
[1217] What are factory and singleton classes? - (2007-06-04)
[1321] Resetting session based tests in PHP - (2007-08-26)
[1387] Error logging to file not browser in PHP - (2007-10-11)
[1487] Efficient PHP applications - framework and example - (2007-12-28)
[1505] Script to present commonly used images - PHP - (2008-01-13)
[1601] Replacing the last comma with an and - (2008-04-04)
[1665] Factory method example - Perl - (2008-06-04)
[1743] First class functions in Lua lead to powerful OO facilities - (2008-08-07)
[1813] Ajax - going Asyncronous and what it means - (2008-09-28)
[1954] mod_rewrite for newcomers - (2008-12-20)
[2046] Finding variations on a surname - (2009-02-17)
[2145] Using the internet to remotely check for power failure at home (PHP) - (2009-04-29)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2360] Error Handling in Lua with assert and pcall - (2009-08-13)
[2433] Controlling, supressing, enabling PHP error messages - (2009-10-02)
[3179] Oops - I typed ci not vi, and have lost my file ... - (2011-02-21)
Some other Articles
Day and night at ChristmasMy armpit was like a zebra crossingVAT ChangesRock and hard place .. and the relaxing right one wonChanging ImagesOpen Source Training Centre and Courses for 2010Faster network, but not faster browsing until ...All the Cs ... and Java tooWhen should I use Java, Perl, PHP, or Python?And now for some posts a bit more technical