Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Random welcome image.

Featured Replies

I want to generate a random image on a home

page so that each time it is visited the viewer gets

a different pic. I'm sure there are many ways to

do this; I'm looking for a light-weight solution.

 

Thanks in advance.

php random() is what you want, create a file random.php, put code to get a random #, then assign a pic to the #'s, then in the main page call the php page e.g. <?php require('random.php'); ?>

 

google for info on the php random function

Plenty ways, like you said, to get this functionality.

 

Here's a JavaScript example I Google'd for ya quickly: http://www.java-scripts.net/javascripts/Ra...ge-Script.phtml

 

The PHP is probably better a solution due to it's ability to facilitate browsers without JS enabled, however, completely your choice.

 

The JS example would require less investigation :)

this is what i've used in the past

 

php:

<?php

$folder = 'rotate/';

$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';

$img = null;

if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}

if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
	isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
	file_exists( $folder.$imageInfo['basename'] )
) {
	$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
	$file_info = pathinfo($file);
	if (
		isset( $extList[ strtolower( $file_info['extension'] ) ] )
	) {
		$fileList[] = $file;
	}
}
closedir($handle);

if (count($fileList) > 0) {
	$imageNumber = time() % count($fileList);
	$img = $folder.$fileList[$imageNumber];
}
}

if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
	header ("Content-type: image/png");
	$im = @imagecreate (943, 440)
		or die ("Cannot initialize new GD image stream");
	$background_color = imagecolorallocate ($im, 255, 255, 255);
	$text_color = imagecolorallocate ($im, 0,0,0);
	imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
	imagepng ($im);
	imagedestroy($im);
}
}

 

put that in a file called rotate.php

 

create a folder called 'rotate' and stick your images in.

 

Then just use this

 

<img src="rotate.php" alt="blah" />

 

down side is though, the alt text won't alternate, easily fixed mind, i just didn't need the alt text to rotate.

  • Author

Thanks a lot guys, I'll go with PHP to support javascript-less people. Thanks again.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.