duan1443 2013-09-09 23:54
浏览 56

每小时轮换PHP包含的文件

How can I rotate a PHP included file on an hourly rotation schedule?

I have a index.php and four files with some content. I want, for every six hours, a different content-file will be included.

For example, in the first time period:

<?php include 1.php ?>

Some hours later:

<?php include 2.php ?>

Again, some hours later:

<?php include 3.php ?>

I already tried Googling and made something like this:

<?php
// starting date for rotation
$startDate = '2013-09-10';
// array of filenames
$files = array('1.php','2.php','3.php','4.php');

$stamp = strtotime($startDate);
$days = (time() - $stamp) / (0*0*6);
$filesName = $files[$days % count($files)]
?>

<?php include $filesName; ?>

However, this does not work.

How can I fix this?

  • 写回答

1条回答 默认 最新

  • doulu1544 2013-09-10 00:07
    关注

    how about:

    <?php
    $hour=date('G',time());
    if($hour ==0) $hour = 1; //take care of hour 0
    $file=ceil($hour/6);
    
    
    include $file.'.php';
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法