Cron Job重命名网页

First, let me say that I know nothing about Cron Jobs or PHP files, so please keep my newbie status in mind if you are kind enough to reply - (use small words and speak slowly!)

I am the webmaster for our organization's site, and I am trying to do something which should be simple, yet time consuming: Take the main web page on our site and automatically update it during the Thanksgiving and Christmas Holidays. I have already created the specific web pages that I need, and uploaded them to the GoDaddy server, but I really don't have the time to go in and manually rename the pages as the days approach; I'm told that a Cron Job would be just the thing to use to automatically save the existing page and rename the new page.

Here is specifically what I want to do: 1) The file Index.htm, located in the root directory, gets either saved or renamed so that I can go back to it after the Holidays are over. 2) The file now named /Holiday Pages/happy_thanksgiving.htm gets moved to the root directory on November 25th and renamed index.htm Same thing with the file named merry_christmas.htm on December 24th. 3) GoDaddy has a Cron Job control panel which allows me to run a specific script on a certain day at a certain time, so I don't think the date codes would need to be embedded into the script itself - but I've not a clue what to put in this script - from talking to the folks at GoDaddy, they suggest a PHP script. 4) Within this PHP script, exactly what commands would I need to write (specific examples please - a sample script would be awesome and MOST appreciated! 5) What would the extension on this script need to be? .TXT or .PHP ??

Thanks in advance! Again, please remember that I'm in over my head here - and pardon my ignorance!

-------------------------------------------------------UPDATE 111/15/14 -------------------------------------------------------- Here's what I have tried so far, using some of your suggestions - the numbers 1) 2) etc are trial script numbers which were then called by the GoDaddy's Cron Job Manager.

1) ----------------------------------------------

<?php
$target = "/holiday_pages/happy_thanksgiving.html"; 
$newName = "/holiday_pages/index.htm";
$renameResult = rename($target, $newName);
// Evaluate the value returned from the function if needed
if ($renameResult == true) {
echo $target . " is now named " . $newName;
} else {
 echo "Could not rename that file";
}
?>

2) ------------------------------------------------

rename('/holiday_pages/happy_thanksgiving.html', '/holiday_pages/index.htm');

3) ------------------------------------------------

rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 

4) ------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('./HTML/holiday_pages/index.htm','index.htm.bak');
copy('./HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure      if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

5) --------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('../HTML/holiday_pages/index.htm','index.htm.bak');
copy('../HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

6) --------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('/HTML/holiday_pages/index.htm','index.htm.bak');
copy('/HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if     this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

7) ---------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('./holiday_pages/index.htm','index.htm.bak');
copy('./holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

Just create a file and name it, for example holiday_copy.php. Here is the script itself:

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.25') {
    copy('index.htm','index.htm.bak');
    copy('../Holiday Pages/happy_thanksgiving.htm','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
    copy('index.htm.bak','index.htm');
}
else if ($date == '2014.12.24') {
    copy('index.htm','index.htm.bak');
    copy('../Holiday Pages/merry_christmas.htm','index.htm'); // again, you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.12.27') {
    copy('index.htm.bak','index.htm');
}

?>

you have to run this script on the desired days, best will be at

0:01 on eg 2014-12-24

You need to place this file in the root directory, where your index.htm is located. If you don't want this, add the appropiate path to all the copied files inside this script - eg here:

copy('index.htm','index.htm.bak');

Be sure to have the rights to access all the directories and files! Remember to call it on the days after the holiday in order to get your old index.htm back.

Better solution is create the files and code dynamically include file according to the date, example code is given below:

$date = date("m-d-y", time());  // current date

$holidays = array('12-25-14' => 'christmas-page.php', '11-27-14' => 'thanksgiving-day-page.php'); // create all holidays here

$page = isset($holidays[$date]) ? $holidays[$date] : 'default-index.php';

include($page);

Simple logic, will work fine

This is not a PHP solution. This is a SSH/Command Line solution, Nor is it a Cron Job. Takes about 2-5 minutes.

Assuming you are on a Linux hosting plan, and that SSH (remote log in) is enabled for your account; If not, you can ask/call GoDaddy to enable this feature for your account.

Once you are on the command line, do the following.

Safety first, so backup all the files we are gonna move around or mess with:

  1. cd PUBLIC_ROOT_DIR
  2. cp "index.htm" "index.htm.bak"
  3. cp "Holiday Pages/happy_thanksgiving.htm" "Holiday Pages/happy_thanksgiving.htm.bak"
  4. cp "Holiday Pages/merry_christmas.htm" "Holiday Pages/merry_christmas.htm.bak"

Before thanksgiving:

  1. cd PUBLIC_ROOT_DIR
  2. mv "index.htm" "index.htm.off"
  3. mv "Holiday Pages/happy_thanksgiving.htm" "index.htm"

After thanksgiving:

  1. cd PUBLIC_ROOT_DIR
  2. mv "index.htm" "happy_thanksgiving.htm.off"
  3. mv "index.htm.off" "index.htm"

Before Christmas:

  1. cd PUBLIC_ROOT_DIR
  2. mv "index.htm" "index.htm.off"
  3. mv "Holiday Pages/merry_christmas.htm" "index.htm"

After Christmas:

  1. cd PUBLIC_ROOT_DIR
  2. mv "index.htm" "merry_christmas.htm.off"
  3. mv "index.htm.off" "index.htm"

As many of you mentioned, a CRON JOB was not a good option; rather a redirect script that takes the web user to the correct page based on the server date. I was able to get some great help from a friend who does programming for a living - and, although this post is well over a year old, I thought I'd share the final result and working script on the chance that others might have the same problem. Note that this script is installed in the root of the web server and named "index.html". A web page is also created which is used for non-holiday use, called "main.html" and the script uses this page if the list of conditions aren't met.

This solution works very well for us, and I greatly appreciate all of the responses!

 <!DOCTYPE html>
<!--
-->
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

    <script type="text/javascript">
        var today = new Date();

        var newyear1 = new Date("2016-12-30");
        var newyear2 = new Date("2016-01-05");

    var valentines1 = new Date("2016-02-14");
        var valentines2 = new Date("2016-02-16");

    var spring_forward1 = new Date("2016-03-07");
        var spring_forward2 = new Date("2016-03-16");

        var easter1 = new Date("2016-03-20");
        var easter2 = new Date("2016-03-29");

    var easter3 = new Date("2016-03-28");
        var easter4 = new Date("2016-03-30");

    var mothers_day1 = new Date("2016-05-07");
        var mothers_day2 = new Date("2016-05-11");

    var memorial_day1 = new Date("2016-05-27");
        var memorial_day2 = new Date("2016-06-02");

    var fathers_day1 = new Date("2016-06-18");
        var fathers_day2 = new Date("2016-06-21");

    var july_4th1 = new Date("2016-07-04");
        var july_4th2 = new Date("2016-07-06");

    var laborday1 = new Date("2016-09-04");
        var laborday2 = new Date("2016-09-09");

    var election1 = new Date("2016-11-07");
        var election2 = new Date("2016-11-10");

    var thanksgiving1 = new Date("2016-11-20");
        var thanksgiving2 = new Date("2016-11-30");

    var xmas1 = new Date("2016-12-10");
        var xmas2 = new Date("2016-12-30");

        // default index page. if no date ranges match, this page will     be     used.
        var pageName = "main.html";


        // new_year 2016
        if(today >= newyear1 && today <= newyear2)
        {
            pageName = "/holiday_pages/happy_new_year.html";
        }

        // Valentines 2016
        if(today >= valentines1 && today <= valentines2)
        {
            pageName = "/holiday_pages/valentines.html";
        }

        // time_change_forward 2016
        if(today >= spring_forward1 && today <= spring_forward2)
        {
            pageName = "/holiday_pages/spring_forward.html";
        }

        // Easter General 2016
        if(today >= easter1 && today <= easter2)
        {
            pageName = "/holiday_pages/easter_1.html";
        }

        // Easter Resurrection 2016
        if(today >= easter3 && today <= easter4)
        {
            pageName = "/holiday_pages/easter_2.html";
        }

        // Mothers Day 2016
        if(today >= mothers_day1 && today <= mothers_day2)
        {
            pageName = "/holiday_pages/mothers_day.html";
        }

        // Memorial Day 2016
        if(today >= memorial_day1 && today <= memorial_day2)
        {
            pageName = "/holiday_pages/memorial_day.html";
        }

         // Fathers Day 2016
        if(today >= fathers_day1 && today <= fathers_day2)
        {
            pageName = "/holiday_pages/fathers_day.html";
        }

        // July 4th 2016
        if(today >= easter3 && today <= july_4th)
        {
            pageName = "/holiday_pages/july_4th.html";
        }

        // labor_day 2016
        if(today >= laborday1 && today <= laborday2)
        {
            pageName = "/holiday_pages/labor_day.html";
        }

        // Election Day 2016
        if(today >= election1 && today <= election2)
        {
            pageName = "/holiday_pages/election_day.html";
        }

        // Thanksgiving 2016
        if(today >= thanksgiving1 && today <= thanksgiving2)
        {
            pageName = "/holiday_pages/happy_thanksgiving.html";
        }

        // Christmas 2016
        if(today >= xmas1 && today <= xmas2)
        {
            pageName = "/holiday_pages/merry_christmas.html";
        }



        // redirect to pageName
        document.location.href = pageName;

    </script>
 </body>
 </html>