# Random include

**URL:** <https://forum.kirupa.com/t/random-include/274489>\
**Category:** programming\
**Created:** [October 30, 2008, 4:53pm UTC](https://forum.kirupa.com/t/random-include/274489 "2008-10-30T16:53:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rocketrud](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rocketrud](https://forum.kirupa.com/u/Rocketrud)\
**Post date:** [October 30, 2008, 4:53pm UTC](https://forum.kirupa.com/t/random-include/274489/1 "2008-10-30T16:53:05Z")

</div>

I need a way to randomly include a file from a directory. It has to be random but over the course of the day they need to be displayed equally.

I’ve tried this but i can’t get it to work and its just random not random but equal  
\<?  
$path = ‘thanksgiving/includes’; // remeber trailing slash!  
$handle = opendir ($path);  
while (($filename = readdir ($handle)) !== false)  
{  
if ($filename != ‘.’ && $filename != ‘…’)  
{  
$file\_array[] = $filename;  
}  
}

$rand = rand (0, count ($file\_array));  
include ($path . $file\_array[$rand]);

?\>

I would like to use file\_get\_contents in the include if that would be possible

Any help would be appreciated.
