Unstoppable Domains

Randomize code?

Spaceship Spaceship
Watch

I Brian

New Member
Impact
0
Sorry to ask a simple question, but I'm looking to randomise a display of content, which are called up with basic PHP include files.

So if there are 5 images, I'm calling them up as:

Code:
<!-- site content above --> 
<?PHP include("/home/user/public_html/section1.php"); ?> 
<?PHP include("/home/user/public_html/section2.php"); ?> 
<?PHP include("/home/user/public_html/section3.php"); ?> 
<?PHP include("/home/user/public_html/section4.php"); ?> 
<?PHP include("/home/user/public_html/section5.php"); ?>
<!-- footer below -->


How would I randomise with a script within the body itself?

Many thanks for any replies.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
do you want to randomize the section1, section2, section3, etc?

or do you want to randomize something INSIDE section1, section2, etc?

here's a link to the php random manual anyway: http://us3.php.net/rand
 
0
•••
That's it rand() should do the trick.
I would do something like... (untested)
PHP:
<!-- site content above --> 
<?PHP include("/home/user/public_html/section".rand(1,5).".php"); ?> 
<!-- footer below -->
 
0
•••
The trouble is trying to get the files 1-5 to be returned in a random order -

ie,

page load: file 5, file 3, file 1, file 4, file 2
refresh: file 3, file 2, file 5, file 1, file 4
refresh again: file 2, file 4, file 1, file 3, file 5
 
0
•••
Something like that maybe...

PHP:
<?php
srand((float) microtime() * 10000000);
$input = array("section1.php", "section2.php", "section3.php", "section4.php", "section5.php");
//$input = array_rand($input, sizeof($input));
foreach (array_rand($input, sizeof($input)) as $i) {
            include("/home/user/public_html/".$input[$i]); 
}
?>
 
0
•••
That worked dgaussin - many thanks for that. :)
 
0
•••

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back