Site Reference Forums

You are not logged in.

#1 2007-11-07 16:07:17

PeterP
Member
From: New York City
Registered: 2005-09-21
Posts: 71
I've been thanked 1 times.

Thank me Website

random image

I want to have several images picked randomly on my homepage when someone visits.  I was going to do a gif or flash animation but I don't think anyone stays on it long enough to bother.

Does anyone know if there's a simple way in html or java to have it pick one of several images to use?

I searched here for a post on that but nothing came up.

P


PeterP   %^)
=================
http://www.positively-organic.com
organic cotton baby clothes

Offline

 

#2 2007-11-07 17:33:14

Steven_A_S
Member
From: San Antonio, TX
Registered: 2006-08-07
Posts: 465
I've been thanked 22 times.

Thank me Website

Re: random image

HTML by itself couldn't do it.  Javascript probably could, but it's something more efficiently done on the server side if you have access to php or asp. I could probably help with a bit of php code if you can use that.

Offline

 

#3 2007-11-07 18:43:49

PeterP
Member
From: New York City
Registered: 2005-09-21
Posts: 71
I've been thanked 1 times.

Thank me Website

Re: random image

I have some access to php but it's through yahoo so i'm not exactly sure if it's what I would need.

I know I can't do php redirects with them.

I copied the list of functions I can use if you want to see.  it's here if it's any help:
http://users.rcn.com/ppossenti/php_functions.rtf


PeterP   %^)
=================
http://www.positively-organic.com
organic cotton baby clothes

Offline

 

#4 2007-11-08 01:04:36

Ryan_steyn
Member
From: South Africa, Port Elizabeth
Registered: 2006-08-23
Posts: 1743
I've been thanked 31 times.

Thank me 
Buy me a beer

Re: random image

here you go, this is some nifty php script i picked up a while back... incredibly simple, you just need to put it a folder with a text file called "random.txt", but i will put the readme below as well to explain how it works... incredibly simple and very functional.

RANDOM.PHP

Code: php

<?php
/************************************************************************/
/* PHP RandomRotator v1.0                                               */
/* ===========================                                          */
/*                                                                      */
/*   Written by Steve Dawson - http://www.stevedawson.com               */
/*   Freelance Web Developer - PHP, Perl and Javascript programming     */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/************************************************************************/
##  HTML or plain text can be randomised. see associated random.txt for the quotes/html.
##  See the associated ReadMe.txt file for full installation instructions.

## The name of the .txt file which hold the rotating info (currently random.txt)
$filename = "random.txt";
$file = file($filename);

  srand((double)microtime()*1000000);
  while ($RandomRotator == "") {
  $RandomRotator = ereg_replace("\n","",$file[rand(0,count($file))]);
  }

## This prints the banner, quotes or random text, or whatever is in the random.txt file
  print "$RandomRotator";
?>


README

Code:

------------------------------------------------------------------------------
 PHP  RandomRotator v1.0
------------------------------------------------------------------------------

Freelance Web Developer -  PHP, Perl and Javascript programming
Web:  www.stevedawson.com
Written by Steve Dawson

After unzipping the randomrotator.zip you should have the following files:

random.php - The random banner generator
random.txt - The list of HTML banners you want to rotate
ReadMe.txt - The file you are reading now!

-------------------------------------------------------------------------------
  OVERVIEW
-------------------------------------------------------------------------------

The simplest way to add banner ads to your website without the need for a database. PHP RandomRotator will also randomise anything you want including: - Plain text, Images, Banners, Quotes, and Links etc. You can place any number of banners, any size, anywhere on your website by using one simple line of code. In fact you could include whole html webpages, so visitors to your site will get a different page every time they visit! PHP RandomRotator uses a flat text file so no database is required.

PHP RandomRotator can be used for a wide number of things including, Banner Ad rotation, Display random quotes, test links, text paragraphs/stories or even can be used to display full webpages. If you want it randomising and it can be typed, then RandomRotator is the script for the job!

FETAURES:
 - Add an unlimited number of Banners.
 - HTML code for text links.
 - A wide number of uses.
 - No database is required.
 - Easy and simple to use.
 - No special PHP or HTML knowledge required.


REQUIREMENTS
PHP enabled web server
Text Editor, such as notepad etc.

INSTALLATION

To install the PHP RandomRotator all you have to do is upload the above files in the directory where your HTML pages are copy and paste the code below into your website where you want the banners to appear. It may be wise to make sure that all the banners are the same size; otherwise your page may look uneven.

Code:   <?PHP include "random.php" ?>

The only file you need to edit is the random.txt file. This is where you will place the banner HTML code etc.

ADDING/REMOVING BANNERS
To add a new banner, simply open up the random.txt file in a text browser and type in the code for your new banner. Ensure all code for each banner is on the same line as a carriage return denotes a new banner. Use the example below as your pattern:

<a target="new" href="http://www.stevedawson.com"><img src="your-image-url-here.gif" border="0"></a>

Deleting a banner is just a case of deleting the whole line of text, to, which the banner applies. Ensure you still leave a carriage return at the end of the preceding line.

EXTRAS
To use this script to display random text or quotes. Simply add your lines of text to the random.txt file and then hit the enter button. This will create a 'carriage return', which the script recognises as the end of the quote.

SIMPLE FAQ'S
No banners are appearing on my site?
Make sure you have a PHP enabled web server.

The same banner keeps appearing, what's happening?
You have probably added the same banner a couple of times, or you may have only one banner in the random.txt file. This will only display one banner!

I get a PHP error when I refresh the pages to see the banners, Why is this?
This means that you have not added a carriage return (press enter) at the end of your lines of html or text. This will produce an error message. Ensure you have not changed any of the file names, as this will also produce error messages.

-------------------------------------------------------------------------------
THIS SCRIPT IS AS IS. UNDER NO CIRCUMSTANCES CAN I BE HELD
RESPONSIBLE FOR ANYTHING TO DO WITH THIS SCRIPT.

**** For more free scripts visit www.stevedawson.com ****

RANDOM.TXT

Code: html

The right half of the brain controls the left half of the body. This means that only left handed people are in their right mind.<br><b><i>Unknown</i></b>
Whatever is not nailed down is mine.<br>What I can pry loose is not nailed down.<br><b><i>Unknown</i></b>
Reality is for people who lack imagination and<br>too much imagination is caused by a lack of reality.<br><b><i>Dave Chadwick 1999</i></b>
Work to Live not Live to Work.<br><b><i>Unknown</i></b>
There is never enough time, unless you're serving it.<br><b><i>Malcolm Forbes</i></b>
I want to die in my sleep like my grandfather....<br>Not kicking and screaming  like his passengers...<br><b><i>Unknown</i></b>
Ever stop to think, and forget to start again.<br><b><i>Steve Dawson 2002</i></b>
Time is what keeps everything from happening at once.<br><b><i>Unknown</i></b>
Only those who dare to fail greatly can ever achieve greatly.<br><b><i>Robert F Kennedy</i></b>
Sometimes I wake up grumpy, Other times I let her sleep.<br><b><i>Unknown</i></b>
Ambition is a poor excuse for not having the sense to be lazy.<br><b><i>Charlie McCarthy</i></b>
Women who seek to be equal to men lack ambition.<br><b><i>It wasn't me!</i></b>
When there's a will, I want to be in it!<br><b><i>Unkown</i></b>
I don't suffer from insanity, I enjoy every minute of it!<br><b><i>Steve Dawson 2002</i></b>
Always remember you're unique, just like everyone else.<br><b><i>Unknown</i></b>
By the time a man realises that maybe his father was right, he usually has a son who thinks he's wrong.<br><b><i>Charles Wadsworth</i></b>
For some, life itself is the biggest pain of all.<br><b><i>Unknown</i></b>
Some say I am crazy....but the Voices in my head disagree.<br><b><i>Steve Dawson 2002</i></b>
You know that children are growing up when<br>they start asking questions that have answers.<br><b><i>John J. Plomp</i></b>
Reason has always existed, but not always in a reasonable form.<br><b><i>Karl Marx</i></b>
The difference between the impossible<br>and the possible lies in determination.<br><b><i>Tommy Lasorda</i></b>
If you can spend a perfectly useless afternoon in a perfectly useless manner, then you have learned how to live.<br><b><i>Lin Yutang</i></b>
The first half of our lives is ruined by our parents, and the second half by our children.<br><b><i>Clarence Darrow</i></b>
Nothing succeeds like a parrott with no teeth.<br><b><i>Betty Dawson 2002</i></b>
It wasn't me, I didn't do it, you can't prove a thing.<br><b><i>Bart Simpson 2000</i></b>
Put your trousers on son - Your Nicked !<br><b><i>Jack Regan</i></b>
If you're lying, I'll be back!<br><b><i>The Exterminater</i></b>

Last edited by Ryan_steyn (2007-11-08 01:05:42)


"Humans are by far the most fascinating creatures, in a universe with no boundaries and a world with so much unfound wonder we are the only entities capable of creating boredom"

Offline

 

#5 2007-11-08 17:06:37

PeterP
Member
From: New York City
Registered: 2005-09-21
Posts: 71
I've been thanked 1 times.

Thank me Website

Re: random image

Not sure if that will work, I want to rotate images within an html page.

I'll look on that dude's website tho.

thx


PeterP   %^)
=================
http://www.positively-organic.com
organic cotton baby clothes

Offline

 

#6 2007-11-08 17:19:11

PeterP
Member
From: New York City
Registered: 2005-09-21
Posts: 71
I've been thanked 1 times.

Thank me Website

Re: random image

Ok I searched around and found out a nice php script to do this.

Guess I should have looked around first eh? blinka

here tis' for anyone interested:

http://www.biglickmedia.com/misc/php/random-image.php

i did a test page and it seems to work!

P


PeterP   %^)
=================
http://www.positively-organic.com
organic cotton baby clothes

Offline

 

#7 2007-11-08 23:37:32

Ryan_steyn
Member
From: South Africa, Port Elizabeth
Registered: 2006-08-23
Posts: 1743
I've been thanked 31 times.

Thank me 
Buy me a beer

Re: random image

PeterP wrote:

Not sure if that will work, I want to rotate images within an html page.

I'll look on that dude's website tho.

thx

Thats what the script was for? <?php include('random.php') ?>

Oh well, st least you found another one anyway tongue


"Humans are by far the most fascinating creatures, in a universe with no boundaries and a world with so much unfound wonder we are the only entities capable of creating boredom"

Offline

 

#8 2007-11-09 02:33:11

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2629
I've been thanked 63 times.

Thank me Website
Buy me a beer

Re: random image

You've asked two different questions; which one do you want?

Do you want a selection of random images to be displayed on your home page? - This is what you asked in your firts post

OR

Do you want to rotate the images? - ie show an image, then replace it with another, and another etc etc while the use looks at the page without doing anything

Both are possible with javascript, php, asp - whatever floats your boat - but make sure you know what you want before asking!

For an example of PHP pulling in random images every time the page is loaded see here - http://yorkoutdoorgroup.org.uk/index2.php [hit refresh and you'll see a different selection of images]

For an example of javascript rotating images see here - http://www.go-ballistic.co.uk/
[a separate gallery page is populated dynamically by a script that reads what images are on the server]


Now taking free-lance inquiries; Please contact me for more details
Internet Marketing Books
Promote Yourself on Site Reference!

Offline

 

#9 2007-11-09 08:35:52

PeterP
Member
From: New York City
Registered: 2005-09-21
Posts: 71
I've been thanked 1 times.

Thank me Website

Re: random image

sorry thought i was clear.  I knew what I was talking about! blinka

I want the homepage to come up with a different image randomly picked from a folder of images I have set up when someone visits it.  So it looks like the front page has changed even though I haven't done anything to it.

As I said in the first post, I don't really need it to rotate while someone is on it because I don't think people stay on the home page long enough to bother with that.

the link i posted has a script that seems to work ok, haven't had a chance to put it in the actual page yet tho.


PeterP   %^)
=================
http://www.positively-organic.com
organic cotton baby clothes

Offline

 

#10 2007-11-11 12:27:15

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2629
I've been thanked 63 times.

Thank me Website
Buy me a beer

Re: random image

look at the php manual for the dir() class

then read up quickly on arrays (as the directory class output is best sent to an array)

Then look at how to pick a random number

what you'll get every time the page loads is an array of all the files in the given folder

Then you'll want to pick a random array element


Now taking free-lance inquiries; Please contact me for more details
Internet Marketing Books
Promote Yourself on Site Reference!

Offline

 
Never
Sponsored Results


Board footer

Powered by PunBB
© Copyright 2002–2008 Rickard Andersson