Loading multiple index pages...

Discussion in 'Web Design and Development' started by nsutt22, Jun 27, 2006.

  1. nsutt22 macrumors regular

    nsutt22

    Joined:
    May 5, 2005
    #1
    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!
     
  2. thejadedmonkey macrumors 604

    thejadedmonkey

    Joined:
    May 28, 2005
    Location:
    Pa
    #2
    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.
     
  3. nsutt22 thread starter macrumors regular

    nsutt22

    Joined:
    May 5, 2005
    #3
    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?
     
  4. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005
    #4
    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.
     
  5. nsutt22 thread starter macrumors regular

    nsutt22

    Joined:
    May 5, 2005
    #5
    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?
     
  6. crees! macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #6
    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.
     
  7. nsutt22 thread starter macrumors regular

    nsutt22

    Joined:
    May 5, 2005
    #7
    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?
     
  8. crees! macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #8
    Can you post the real address so we can look?
     
  9. nsutt22 thread starter macrumors regular

    nsutt22

    Joined:
    May 5, 2005
    #9
    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?
     

Share This Page