Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nsutt22

macrumors regular
Original poster
May 5, 2005
177
0
Ok I would like my homepage to load differnt indexes each time. There are like 6 indexes and each have a differnt image. I would like them to load at random? Anythoughts?

Thanks!
 
If you mean to load a random image each time, a bit of javascript jandom goodness can do it for you. If, by randomness you mean an entire layout, I'd go with a basic PHP script that uses a random include file. Google would be your friend here.
 
hurray! google. I will start searching. so the php will just be for the main index load then right? then i wont need php for the other links?
 
Assuming your server supports PHP... this is a simple way to do it:

PHP:
<?php
$pages = "
index1.html
index2.html
index3.html
index4.html
";

$indexes = explode("\n", $pages);
foreach ($indexes as $key => $line) {
    $line = trim(str_replace("\r", '', $line));
    if (!empty($line)) $files[] = $line;
}

$randomKey = rand(0, (count($files)-1));

include ($files[$randomKey]);
?>

(I included extra code to make it easier on you if you don't know PHP)

Just put each index file between the quotes, each on a new line, and it will include a random one of those.
 
Coolnat2004 said:
Assuming your server supports PHP... this is a simple way to do it:

PHP:
<?php
$pages = "
index1.html
index2.html
index3.html
index4.html
";

$indexes = explode("\n", $pages);
foreach ($indexes as $key => $line) {
    $line = trim(str_replace("\r", '', $line));
    if (!empty($line)) $files[] = $line;
}

$randomKey = rand(0, (count($files)-1));

include ($files[$randomKey]);
?>

(I included extra code to make it easier on you if you don't know PHP)

Just put each index file between the quotes, each on a new line, and it will include a random one of those.

Thanks a bunch. since the server auto loads an index.html file how do i make it load the index.php file?
Also how do I preview to see if this works. Cause i cant just open th index.php file in a browser? or can I?
 
nsutt22 said:
Thanks a bunch. since the server auto loads an index.html file how do i make it load the index.php file?
Also how do I preview to see if this works. Cause i cant just open th index.php file in a browser? or can I?

It should load the PHP first if one is present, I think. If not just make sure you don't have an index.htm(l) file.

EDIT: Yes, just load the PHP file in whatever browser. It must be on a server, not your local machine.
 
Ok... i made a .php file... here is le code

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>

and it is saved as hello.php

I then placed it on the exchange server and tried to open like this
http://www.mywebsite.com/hello.php

It did not open. I am goofing something any ideas?
 
It is put in the same diretory as my working index.html but i named it hellp.php
EDIT: It looks like nothing is there... how wierd?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.