_Chris Posted February 16, 2011 Share Posted February 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/ Share on other sites More sharing options...
waterssaz Posted February 16, 2011 Share Posted February 16, 2011 Are you trying to create some kind of dynamic footer I take it but purely with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1174941 Share on other sites More sharing options...
_Chris Posted February 16, 2011 Author Share Posted February 16, 2011 Are you trying to create some kind of dynamic footer I take it but purely with PHP? Are you trying to create some kind of dynamic footer I take it but purely with PHP? Yep. Any ideas at all please? Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1174943 Share on other sites More sharing options...
waterssaz Posted February 16, 2011 Share Posted February 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1174952 Share on other sites More sharing options...
_Chris Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks waterssaz, I notice the rand in there, is that to ensure that the images within the php files get randomized please? If so, that's great. Also, would the php files chnage on on each user refresh / page load ? Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1174962 Share on other sites More sharing options...
waterssaz Posted February 16, 2011 Share Posted February 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1174999 Share on other sites More sharing options...
_Chris Posted February 17, 2011 Author Share Posted February 17, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/227855-different-php-include-on-refresh-or-page-load/#findComment-1175536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.