Jump to content

Need help rotate code $10 e-gold for best usable reply

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
kilop

kilop

    Newbie

  • Members
  • Pip
  • 2 posts
Hi
I need a way to change a page on every refresh
This is the code I have (the part that matters)
<div id="body">
<?php include('1.php'); ?>
<?php include('2.php'); ?>
<?php include('3.php'); ?>
<?php include('4.php'); ?>
<?php include('5.php'); ?>
</div>
I need to either randomize or rotate the order of the php files on every refresh, preferably rotate.

so 1-2-3-4-5 refresh 2-3-4-5-1 and so on (or randomize)
what's the best way to do it?
I don't mind completely changing the code, the order can be randomized but all must appear without repetition.
Thanks

Edited by Jaan, 22 May 2008 - 03:16 AM.
If you're posting your codes, use [code] tags!


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
<?php
echo '<div id="body">';

$input = array("1.php", "2.php", "3.php", "4.php", "5.php");
$rand_keys = array_rand($input, sizeof($input));
for($i = 0; $i < sizeof($input); $i++) {
	include($input[$rand_keys[$i]]);
}

echo '</div>'
?>
Or
<?php
echo '<div id="body">';

$input = array("1.php", "2.php", "3.php", "4.php", "5.php");
shuffle($input);
foreach ($input as $files) {
    include($files);
}

echo '</div>'
?>

Note: This the second method assigns new keys to the elements in array . It will remove any existing keys that may have been assigned, rather than just reordering the keys. Although that might be a drawback, it is more efficient - but if is a concern, use the first method.


Don't worry about the E-Gold :)

Edited by John, 21 May 2008 - 02:39 PM.


#3
kilop

kilop

    Newbie

  • Members
  • Pip
  • 2 posts
Thank you for the fast reply, this is a great forum, will recommend to everyone.
PM sent

#4
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
what the heck is egold, lol
Checkout my new forum! http://adminreference.com/

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Its like paypal.

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Isn't there an mt_rand() function that just accepts the upper and lower bounds as parameters? You could just do that, then concatenate it with the .php extension.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Xav said:

Isn't there an mt_rand() function that just accepts the upper and lower bounds as parameters? You could just do that, then concatenate it with the .php extension.

mt_rand will return a single value between the upper and lower bound. If you do this in a loop, there is no guarantee all the numbers will be unique without repetition.

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Oh - that's pretty clever. I suppose it's useful if you just wanted to load one php file out of the lot.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Xav said:

Oh - that's pretty clever. I suppose it's useful if you just wanted to load one php file out of the lot.

Indeed.

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I'm so proud of myself - I got something right. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums