fudgepuppy
fudgepuppy

Reputation: 105

Random image upon refresh with only one single image URL

Tried googling for a readily available script, but to no avail. I'm trying to find a script that does the below. Im not sure of there is a name for it.
Thank you in advance!

Function: Banner rotator with a single URL (PHP based)

Example:
User uploads 5 images (468x60px)
The system generates a a single image URL (e.g. http://demo.com/image.gif)
When user goes to the generated URL, it randomly shows 1 of his 5 images
Every time he refreshes the URL, it randomly shows him another one of his images

Upvotes: 0

Views: 910

Answers (1)

Eric J.
Eric J.

Reputation: 150108

You can have the server-side code that processes the given URL return a random image each time. If you specify the server-side language (PHP, ASP.Net, JSP, ...) that you are using, I can give an example.

The URL can be something like

http://demo.com/image/

It does not need to have a specific image name in it.

The key is to ensure that the browser does not try and cache that URL. Set appropriate cache headers when returning the image. Again, the mechanics of doing that are specific to your language.

PHP Example

This short tutorial shows you now to select a random image from a folder of images

http://www.heckdesigns.com/tutorials/tutorial-pull-in-a-random-image-from-a-folder-with-php/

URL

You really should not have to require your URL to end in .png or whatever. If you set the Content-Type appropriately (as the tutorial above does), any web browser should display it properly. If that is in fact a requirement, you can use Apache rewrite rules to do that.
See

mod_rewrite and image redirecting

Upvotes: 1

Related Questions