PX : code

CountDown by Le Viet Thang
Download this code


<?php

// Writen by LE VIET THANG (webmaster@allotaiwan.com, thangleviet@hotmail.com)

// If you want to try this script, please visit http://www.allotaiwan.com/my_scripts/countdown.php3

//////////////////// CHANGE THIS SECTION BEFORE USING //////////////////////
$date "18\";      // correct dates are from 01 to 31
$month = \"05\";     // correct months are from 01 to 12
$year = \"2001\";         // correct years are from 1970 to 2037

$seconds = \"00\";      // from 00 to 59
$minutes = \"30\";      // from 00 to 59
$hour = \"11\";         // from 00 to 23

$method = \"1\";         // you can choose 1, 2 or 3

// methods to use when the countdown stops
// method 1 : display a message
$countdown_stop_message = \"Happy birthday to you !\";
// method 2 : open a new URL
$countdown_stop_url = \"http://www.allotaiwan.com\";
// method 3 : execute your own php script
$countdown_stop_require = \"my_file.php3\";    
// be careful, if \"my_file.php3\" doesn\'t exist, you will see an error message
// so you must create a blank file named \"my_file.php3\"

//////////////////////////////// OK STOP HERE //////////////////////////////

///////////////////////////////FUNCTIONS SECTION - DO NOT MODIFY //////////
function error($error)
{
print(\"<h3><font face=arial><b>Error : </b>$error</font></h3>\");
}

function message($message)
{
print(\"<h3><font face=arial>$message</font></h3>\");
}

function execute_method($method, $method_variable)
{
         if($method == \"1\"){
         message(\"$method_variable\");
         }
         elseif($method == \"2\"){
         print(\"<html><head><meta http-equiv=\\\"Refresh\\\" content=\\\"1;URL=$method_variable\\\"></head><body></body></html>\");
         }
         else{
         require(\"my_file.php3\");
         }
}

function countdown($countdown, $countdown_type, $countdown_gap, $countdown_gap_type, $hour, $minutes, $seconds, $month, $date, $year)
{
print(\"There are about $countdown $countdown_type\");
       if($countdown > 1){print(\"s\");}
       if($countdown_gap >= 1){
            print(\" and $countdown_gap $countdown_gap_type\");
              if($countdown_gap > 1){print(\"s\");}
       }
print(\" before the $date/$month/$year at $hour\".\":\".\"$minutes\".\":\".\"$seconds\");
}
////////////////////////////  END OF FUNCTIONS SECTIONS ///////////////////

if(checkdate($month,$date,$year)){

$this_moment = time();
$date_to_go = mktime($hour, $minutes, $seconds, $month, $date, $year);
$gap = $date_to_go - $this_moment;

if($date_to_go <= $this_moment){
    if($method == \"1\"){
    $method_variable = $countdown_stop_message;
    execute_method($method, $method_variable);
    }
    if($method == \"2\"){
    $method_variable = $countdown_stop_url;
    execute_method($method, $method_variable);
    }
    if($method == \"3\"){
    $method_variable = $countdown_stop_require;
    execute_method($method, $method_variable);
    }
     }
if($date_to_go > $this_moment){
           if($gap >= 86400){
           $countdown_type = \"day\";
           $countdown = floor($gap / 86400);
           $countdown_gap = floor(($gap - ($countdown * 86400)) / 3600);
           $countdown_gap_type = \"hour\";
           countdown($countdown, $countdown_type, $countdown_gap, $countdown_gap_type, $hour, $minutes, $seconds, $month, $date, $year);
           }
           if(($gap < 86400) AND ($gap > 3600)){
           $countdown_type = \"hour\";
           $countdown = floor($gap / 3600);
           $countdown_gap = floor(($gap - ($countdown * 3600)) / 60);
           $countdown_gap_type = \"minute\";
           countdown($countdown, $countdown_type, $countdown_gap, $countdown_gap_type, $hour, $minutes, $seconds, $month, $date, $year);
           }
           if(($gap <= 3600) AND ($gap > 60)){
           $countdown_type = \"minute\";
           $countdown = floor($gap / 60);
           $countdown_gap = ($gap - ($countdown * 60));
           $countdown_gap_type = \"second\";
           countdown($countdown, $countdown_type, $countdown_gap, $countdown_gap_type, $hour, $minutes, $seconds, $month, $date, $year);
           }
           if($gap <= 60){
           $countdown_type = \"second\";
           $countdown = $gap;
           countdown($countdown, $countdown_type, $countdown_gap, $countdown_gap_type, $hour, $minutes, $seconds, $month, $date, $year);
           }
     }
}else{
error(\"Date or time you entered are incorrect !\");
}

?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.