JetJagger Posted October 23, 2008 Share Posted October 23, 2008 I need a script that will allow me to include random 'php includes' in my site, but I am having trouble finding one that works as advertised. The script simply need to allow me to create add various 'php includes' to an array, then I need another string of code that can be inserted into my Web page to pull-in the 'php includes' in the array. For example: ARRAY FILE (Loosely-based on reality)... (arrayfile.php) [1] <?php include('http://whateverfilefromanywhere01.php'); ?> [2] <?php include('http://whateverfilefromanywhere02.php'); ?> [3] <?php include('http://whateverfilefromanywhere03.php'); ?> THEN THE INCLUDE THAT GOES INTO THE WEB PAGE.... (embedded inside Web page) <?php include('http://arrayfilepath.php"); ?> That's it! Keep in mind, I DO NOT need a 'random image' script. There are hundreds of those. What I need is a script that INCLUDES whatever objects or content found in the 'php include' files in the array. These might be images, text, or HTML strings. I don't know why this script is so hard to locate on the Web! Help. Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/ Share on other sites More sharing options...
wildteen88 Posted October 23, 2008 Share Posted October 23, 2008 Do something like $files = array('file1.php', 'file2.php'. 'file3.php'); // randomly include a file include $files[rand(0, count($files)-1)]; Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672920 Share on other sites More sharing options...
rhodesa Posted October 23, 2008 Share Posted October 23, 2008 or with array_rand $files = array('file1.php', 'file2.php'. 'file3.php'); // randomly include a file include $files[array_rand($files)]; Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672922 Share on other sites More sharing options...
wildteen88 Posted October 23, 2008 Share Posted October 23, 2008 or with array_rand Doh! I always forget about that function Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672924 Share on other sites More sharing options...
dropfaith Posted October 23, 2008 Share Posted October 23, 2008 http://socoder.net/index.php?snippet=57 kinda an interesting link regarding this id prob use the method's already mentioned tho Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672925 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 or with array_rand $files = array('file1.php', 'file2.php'. 'file3.php'); // randomly include a file include $files[array_rand($files)]; Except for the . instead of the , in the array Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672930 Share on other sites More sharing options...
redarrow Posted October 23, 2008 Share Posted October 23, 2008 <?php $a=array("http://www.google.co.uk","http://www.msn.co.uk","http://www.yahoo.co.uk"); shuffle($a); echo file_get_contents("$a[0]"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672933 Share on other sites More sharing options...
JetJagger Posted October 23, 2008 Author Share Posted October 23, 2008 STATUS: Okay, they all worked, and I actually found many of those scripts online already. My problem was that I was trying to separate-out the 'echo' or 'array include' portion of the script (so that the file path portion was a stand-alone file). Well, I didn't need to do that since I could just include the whole dang script with a basic include string. DUH! DUH! DUH! Anyway... Thanks to all for such quick responses to this embarrassingly simply question. Three hours wasted on 'trying to hard'. LOL. Quote Link to comment https://forums.phpfreaks.com/topic/129808-i-need-a-simple-random-file-include-script-any-ideas/#findComment-672961 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.