Php 用于重命名网页的Cron作业

Php 用于重命名网页的Cron作业,php,cron,jobs,Php,Cron,Jobs,首先,我要说的是,我对Cron作业或PHP文件一无所知,因此,如果您愿意回答,请记住我的新手状态—(使用小词,慢慢说!) 我是我们公司网站的站长,我正在尝试做一些简单但耗时的事情:在感恩节和圣诞节期间,获取我们网站的主网页并自动更新它。我已经创建了我需要的特定网页,并将其上传到GoDaddy服务器,但随着时间的推移,我真的没有时间进去手动重命名这些网页;我听说Cron作业正是用来自动保存现有页面并重命名新页面的工具 以下是我具体想做的: 1) 位于根目录中的Index.htm文件会被保存或重命名

首先,我要说的是,我对Cron作业或PHP文件一无所知,因此,如果您愿意回答,请记住我的新手状态—(使用小词,慢慢说!)

我是我们公司网站的站长,我正在尝试做一些简单但耗时的事情:在感恩节和圣诞节期间,获取我们网站的主网页并自动更新它。我已经创建了我需要的特定网页,并将其上传到GoDaddy服务器,但随着时间的推移,我真的没有时间进去手动重命名这些网页;我听说Cron作业正是用来自动保存现有页面并重命名新页面的工具

以下是我具体想做的: 1) 位于根目录中的Index.htm文件会被保存或重命名,以便我可以在假期结束后返回。 2) 现在名为/Holiday Pages/happy_Thank.htm的文件在11月25日移动到根目录,并在12月24日重命名为index.htm,与名为merry_christmas.htm的文件相同。 3) GoDaddy有一个Cron作业控制面板,允许我在某一天、某一时间运行特定的脚本,因此我认为不需要将日期代码嵌入脚本本身——但我不知道该在这个脚本中放什么——通过与GoDaddy的同事交谈,他们建议使用PHP脚本。 4) 在这个PHP脚本中,我需要编写什么样的命令(请给出具体的示例-一个示例脚本将非常棒,非常感谢! 5) 此脚本上的扩展名需要是什么。TXT或.PHP

提前谢谢!再一次,请记住,我在这里是在我的头-并原谅我的无知

-------------------------------------------------------更新111/15/14--------------------------------------------------------
rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 
以下是我迄今为止尝试过的,使用了您的一些建议-数字1)2)等是试用脚本编号,然后由GoDaddy的Cron作业经理调用

(一)----------------------------------------------

<?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";
}
?>
rename('/holiday_pages/happy_thanksgiving.html', '/holiday_pages/index.htm');
rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 
<?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');

}
<?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');

}
<?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');

}
<?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');
(三)------------------------------------------------
rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 
(四)------------------------------------------------

<?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";
}
?>
rename('/holiday_pages/happy_thanksgiving.html', '/holiday_pages/index.htm');
rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 
<?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');

}
<?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');

}
<?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');

}
<?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');

只需创建一个文件并将其命名,例如holiday_copy.php。以下是脚本本身:

<?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');
}
您需要将此文件放在index.htm所在的根目录中。如果不希望这样,请将适当的路径添加到此脚本中所有复制的文件-例如:

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

确保您有权访问所有目录和文件!记得在假期后的几天调用它,以便找回旧的index.htm。

更好的解决方案是创建文件,并根据日期动态编写包含文件的代码,下面给出了示例代码:

$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);

简单的逻辑,可以很好地工作

这不是一个PHP解决方案。这是一个SSH/命令行解决方案,也不是Cron作业。大约需要2-5分钟

假设您在Linux托管计划中,并且为您的帐户启用了SSH(远程登录);如果没有,您可以要求/致电GoDaddy为您的帐户启用此功能

进入命令行后,请执行以下操作

安全第一,所以备份我们要移动或处理的所有文件:

  • cd公共\u根\u目录
  • cp“index.htm”“index.htm.bak”
  • cp“Holiday Pages/happy_Thank.htm”“Holiday Pages/happy_Thank.htm.bak”
  • cp“Holiday Pages/merry_christmas.htm”“Holiday Pages/merry_christmas.htm.bak”
  • 感恩节前:

  • cd公共\u根\u目录
  • mv“index.htm”“index.htm.off”
  • mv“Holiday Pages/happy_Thank.htm”“index.htm”
  • 感恩节之后:

  • cd公共\u根\u目录
  • mv“index.htm”“happy_Thank.htm.off”
  • mv“index.htm.off”index.htm
  • 圣诞节前:

  • cd公共\u根\u目录
  • mv“index.htm”“index.htm.off”
  • mv“Holiday Pages/merry_christmas.htm”“index.htm”
  • 圣诞节后:

  • cd公共\u根\u目录
  • mv“index.htm”“圣诞快乐.htm.off”
  • mv“index.htm.off”index.htm

  • 正如你们很多人提到的,CRON工作不是一个好的选择;而是根据服务器日期将web用户带到正确页面的重定向脚本。我从一位以编程为生的朋友那里得到了很大的帮助,尽管这篇文章已经发表了一年多了,但我想我会分享最后的结果和工作脚本,希望其他人也有同样的问题。请注意,此脚本安装在web服务器的根目录中,名为“index.html”。还创建了一个用于非假日使用的网页,称为“main.html”,如果不满足条件列表,脚本将使用该网页

    这个解决方案对我们非常有效,我非常感谢所有的回复

     <!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>
    
    
    var today=新日期();
    var newyear1=新日期(“2016-12-30”);
    var newyear2=新日期(“2016-01-05”);
    var Valentine1=新日期(“2016-02-14”);
    var Valentine2=新日期(“2016-02-16”);
    var spring_forward1=新日期(“2016-03-07”);
    var spring_forward2=新日期(“2016-03-16”);
    var easter1=新日期(“2016-03-20”);
    var easter2=新日期(“2016-03-29”);
    var easter3=新日期(“2016-03-28”);
    var easter4=新日期(“2016-03-30”);
    var mothers_day1=新日期(“2016-05-07”);
    var mothers_day2=新日期(“2016-05-11”);
    var注册摘要第1天=新日期(“2016-05-27”);
    var注册摘要第2天=新日期(“2016-06-02”);
    var fathers_day1=新日期(“2016-06-18”);
    var fathers_day2=新日期(“2016-06-21”);
    var july_4th1=新日期(“2016-07-04”);
    var july_4th2=新日期(“2016-07-06”);
    var Laboraday1=新日期(“2016-09-04”);
    var Laboraday2=新日期(“2016-09-09”);
    风险值选择1=新日期(“2