NameSilo

How to load a different page each time page refreshes?

Spaceship Spaceship
Watch
Hi!
For a new site I am creating, I need to do one of the following options:
- Load a different home page each time user refreshes or enter site (I could be also just changing part of the code in the same page)
- Load different random different images on the home page as a slide show (BUT, it can't be just 1 image. I have a set of 5 images, that need to change to other 5 images).

Do you have any idea how to do eigther those?
It can be a javascript code, HTML, or PHP.

Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Something like this should probably work for everything you're wanting to do with some slight modification.

Add this in your php page somewhere:
PHP:
<?
srand((double)microtime() * 10000000);
$images = array(
"Random image: <img src ="http://yourdomain.ext/pic1.gif" border="0">", 
"Some Random Code: <font color ="blue">This is blue</font>", 
"A Random quote: Some quote",
"Random Image 2:<img src ="http://yourdomain.ext/pic2.jpg" border="0">" 
);
$select = array_rand($images, 1);
$random = $images[$select];
?>
Then add this where ever you want the random picture, code, quote, or whatever else you put in there to show up:
PHP:
<? echo $random; ?>

You can add as many as you'd like just follow the same format. You can make it all images or whatever you want.

You could also make it select a random page using includes and/or a switch statement or something like that. :D
 
0
•••
question

Thanks for the response. But I have a question.
The home page is not in PHP. Should I make another PHO page that will be accessed from the HMTL home page? or I just include that code in the HTML and it will work?
Thanks
 
0
•••
If you want to use that on your page it would need to be a php file. You could just rename your page so it has .php extension rather than a .html extension and throw that code in it if your server supports php.

Otherwise you'll probably want to use JavaScript.
 
0
•••
The problem is that is my index.html page, the home page. SO I can't rename it or won't work, also I don't want to have anothe rindex.html redirecting to this php page.
Is there another solution?
Thanks
 
0
•••
So your host doesn't allow you to use index.php as your default index page?

Have you tried renaming it to index.php to verify that it does or doesn't work?

I would bet that they do, but it is possible they don't.

I know alot of servers will be set up to allow you to use either index.html index.htm index.php index.php3 index.php4 index.shtml and others as the index page. The index pages will probably be searched for similar to that order also. So first it will look for index.html, then if it don't exist, look for index.htm, then index.php etc., just depending on how they have it set up.

Also you can actually rename all your .html files to .php files and they should work just the same. There's no real reason to do that though, unless your going to be using some php code.
 
0
•••
Great

Great it works! I renamed the index,html to index.php

Now, I have a question about the code. I have to set the whole array of images to be randomized right? Can't I just tell the script to go look in a folder and pick one?
Thanks.

What if instead of randomizing images, I want to randomize the HTML code that calls the images? Like in the case I want to load a different set of 5 images each time ?

Thanks again!!!
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back