Jump to content

Different PHP include on refresh or page load ?


_Chris

Recommended Posts

Is there some way of a php include which is visible on every page (footer), itself having two php includes, but only one of which would be visible, then on the user refreshing the page or on visiting another page on the site, that include would be replaced with another php include?  Preferably done without any js.

 

Any help appreciated.

 

Chris

 

Link to comment
Share on other sites

Ok, can't say I've actuallly tried this with jut php before but I could think of a few ways that should work, some will be more graceful than others.

 

One to try then, How about an array of files that you want to include and then use something like

 

<?php 

$files = array("file1.html", "file2.txt", "file3.php", "file4.php"); 
$rand = array_rand($files); 
include ($files[$rand]); 
?> 

You could include this in on each page or to make it more portable incase you change the array, include it in a class file or function and call it from there.

Forgive any syntax errors as I haven't tested it

Hope it helps

Regards

Sarah

Link to comment
Share on other sites

All that snippet of code essentially does is select one of the files from the array at random everytime the page is called, so yes it would change when the page is refreshed and on each visit, although due to the nature of random and depending on how many files you specify this may sometimes stay the same.

 

The files can contain whatever code you want,

 

Regards

Sarah

Link to comment
Share on other sites

Thanks Sarah, each of the 2 files has html for 10 images, so, 10 images in file_one and ten in file_two - and I fully understand about the files being chosen in a random way, but is there any way that the images within those files, being shown in a random order as well?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.