Jump to content

Weekly rotating


sotusotusotu

Recommended Posts

There is probably a much better way of doing this but here is my code:

 

<?php

$txtfile = 'file.txt';
$file1 = "file1.swf";
$file2 = "file2.swf";

$handle = fopen($txtfile, 'rw');
if(filesize($txtfile) > 0) $contents = fread($handle, filesize($txtfile));
else $contents = "";
if(!empty($contents))
{
 $date = explode(',', $contents);
 if(date('D') == "Mon") {
   if($date[0] != date('d')) {
     if($date[1] == $file1) $file = $file2;
     else $file = $file1;
     fwrite($handle, date('d') . ',' . $file);
   }
 }
} else {
 $file = $file1;
 fwrite($handle, date('d') . ',' . $file);
}

echo $file; // Display the swf's name. Change this to whatever.

?>

 

You need an empty file 'file.txt' (you can change the name in the code).

Link to comment
https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502145
Share on other sites

Thanks a lot Laffin.  If the number is "1" now then obviously(hopefully) next week it will be "0". Do you know the exact point it will change? Is it Monday at 00:01 am?

 

Cheers

 

Correct :)

According to php doc on date function

ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)

So it shud start at 00:01 am Monday

Link to comment
https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502150
Share on other sites

There is probably a much better way of doing this but here is my code:

 

<?php

$txtfile = 'file.txt';
$file1 = "file1.swf";
$file2 = "file2.swf";

$handle = fopen($txtfile, 'rw');
if(filesize($txtfile) > 0) $contents = fread($handle, filesize($txtfile));
else $contents = "";
if(!empty($contents))
{
  $date = explode(',', $contents);
  if(date('D') == "Mon") {
    if($date[0] != date('d')) {
      if($date[1] == $file1) $file = $file2;
      else $file = $file1;
      fwrite($handle, date('d') . ',' . $file);
    }
  }
} else {
  $file = $file1;
  fwrite($handle, date('d') . ',' . $file);
}

echo $file; // Display the swf's name. Change this to whatever.

?>

 

You need an empty file 'file.txt' (you can change the name in the code).

 

Thanks a lot for this example.  I think this is actually more detailed than I need but will keep the example as I am sure it will get more complicated in future.

Link to comment
https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502160
Share on other sites

Thanks a lot Laffin.  If the number is "1" now then obviously(hopefully) next week it will be "0". Do you know the exact point it will change? Is it Monday at 00:01 am?

 

Cheers

 

Correct :)

According to php doc on date function

ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)

So it shud start at 00:01 am Monday

 

Thanks a lot mate.

Link to comment
https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502162
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.