Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Randomizing script

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Courtney_G
Novice Poster


Joined: 17 Jan 2008
Posts: 13
Location: SoCal

PostPosted: Mon Jan 21, 2008 2:05 pm    Post subject: Randomizing script Reply with quote

I'm looking for a randomizing script that'll allow me to display an image on a page, and when the page is refreshed display a new random image.

I'm having trouble finding a user friendly script, I'm not the world's greatest at coding, so something a code newb like me could use with little trouble (or even something not so easy if it came with detailed instructions) would be a big help.

Thanks!
Back to top
 
LP-SolidRaven
Dictator of the Dump


Joined: 06 Jun 2004
Posts: 7030
Location: The cheese is made out of moon

PostPosted: Mon Jan 21, 2008 3:29 pm    Post subject: Reply with quote

You leave open too much questions.
Random image as if, you enter the url and it displays a random image from a directory. Or a random image on a page?
_________________
Quote:

<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
Back to top
 
Rashy
Lifeless Person


Joined: 25 Sep 2006
Posts: 637


PostPosted: Mon Jan 21, 2008 4:00 pm    Post subject: Re: Randomizing script Reply with quote

Courtney_G wrote:
I'm looking for a randomizing script that'll allow me to display an image on a page, and when the page is refreshed display a new random image.


I would say he is looking for something that displays on a page with other content (such as a random header rotator, like imusion.net has)

Do you want the script to load the images from a directory, or a list that you specify in the script? And have you checked hotscripts.com? They would likely have the most user friendly scripts.
_________________
Rashy!
Back to top
 
Courtney_G
Novice Poster


Joined: 17 Jan 2008
Posts: 13
Location: SoCal

PostPosted: Mon Jan 21, 2008 4:19 pm    Post subject: Reply with quote

Yeah, sorry, I mean random images from a directory. And I totally forgot to check hotscripts, I used to have a bookmark for the site but I didn't think to check there. Thanks!
Back to top
 
Pie32
Not Banned


Joined: 17 Mar 2005
Posts: 1411
Location: Lost in 84

PostPosted: Mon Jan 21, 2008 7:02 pm    Post subject: Reply with quote

I've got a random image script (slightly modified to not always change) in my signature, actually.

Code:
// array of image URLs
$imgs = array('...');

// random image
$value = array_rand($imgs);

// send it out
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Location: $imgs[$value]");

_________________
[img]http://luneknight.com.ru/counter.jpg[/img]
Random Battle: [img]http://luneknight.com.ru/l.jpg[/img] vs. [img]http://luneknight.com.ru/r.jpg[/img]
Back to top
 
Courtney_G
Novice Poster


Joined: 17 Jan 2008
Posts: 13
Location: SoCal

PostPosted: Tue Jan 22, 2008 12:19 pm    Post subject: Reply with quote

Ok, thanks, that may be just what I need. Um, I feel silly asking, but could you explain how to implement it?
Back to top
 
Rashy
Lifeless Person


Joined: 25 Sep 2006
Posts: 637


PostPosted: Tue Jan 22, 2008 3:30 pm    Post subject: Reply with quote

I'll see if I can get it right. I've added additional comments:

Code:

// array of image URLs
$imgs = array('...');

/* In the line above, you want to list all of your images where the '...' is. This works fine if you have a small number of images. I think it should be in the format: array(0 => "path/to/img1.jpg" "path/to/img2.jpg" "path/to/img3.jpg" "path/to/img4.jpg"); *\

// random image
$value = array_rand($imgs);

// send it out
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Location: $imgs[$value]");


Another option if you want the entire directory:

Code:
if ($handle = opendir('.')) { // Here replace the '.' with '/path/to/directory/'
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $arrayimages = $arrayimages . $file . ",";
        }
    }
    closedir($handle);
}

// array of image URLs
$imgs = array($arrayimages);

//This does the same as above, except it lists the URLS automatically based on the dir you specified.

// random image
$value = array_rand($imgs);

// send it out
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Location: $imgs[$value]");


Its been a while since I last coded PHP, so somebody would have to check up on what I wrote for accuracy (or you can test it and let me know what happens and I might be able to fix it).
_________________
Rashy!
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com