Interesting random PHP include issue

86 views Asked by At

I have what I think is an interesting issue with a random PHP include on a portal for my company's employees/dealers. I have a random inspirational quote appear at the top of the pages and I have the pages set to refresh every 2 minutes. The code grabs a random PHP file from a "quotes" folder so I don't have to do any more coding if i want to add more quotes. It works flawlessly about 90% of the time but every now and then I get the following error:

Warning: include(/home/content/xx/xxxxxxxxx/html/Team/includes/quotes) [function.include]: failed to open stream: Success in /home/content/49/11856349/html/Team/includes/quote.php on line 12

Warning: include() [function.include]: Failed opening '../includes/quotes/' for inclusion (include_path='.:/usr/local/php5_3/lib/php') in /home/content/xx/xxxxxxxxx/html/Team/includes/quote.php on line 12

The following is the PHP code I'm using. I can't seem to see anything wrong with it (given my limited knowledge of PHP as of this writing). If it didn't work at all, it would make more sense than working just fine most of the time. The quote files are all named quote000.php up to quote020.php. I have opened all of the quote files separately in a browser and they all work error free. Incidentally, I'm using the "include" statement...not "include_once, require, etc." Thanks in advance for any advice!

    <?php
    $i=0;
    $myDirectory = dir("../includes/quotes");
    while($file=$myDirectory->read())
      {
        $array[$i]=$file;
        $i++;
      }
    $myDirectory->close();
    $num = count($array);
    $random = rand(0, $num);
    include "../includes/quotes/$array[$random]";
    ?>
0

There are 0 answers