<?php
function DateAdd($date, $int, $unit = "d") { //時間的增加(還可以改進成時分秒都可以增加,有時間再補上)
$dateArr = explode("-", $date);
$value[$unit] = $int; //OSPHP.COm.CN
return date("Y-m-d", mktime(0,0,0, $dateArr[1] + $value['m'], $dateArr[2] + $value['d'], $dateArr[0] + $value['y'])); //OSPHP.COm.CN
}
function GetWeekDay($date) { //計算出給出的日期是星期幾
$dateArr = explode("-", $date);
return date("w", mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0])); }
?>
<?
function GetIP() { //獲取IP
if ($_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ($_SERVER["HTTP_CLIENT_IP"])
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if ($_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"]; getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknown";
return $ip;
}
?> <?
function check_date($date) { //檢查日期是否合法日期
$dateArr = explode("-", $date);
if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) { checkdate($dateArr[1],$dateArr[2],$dateArr[0]);
}
return false;
}
function check_time($time) { //檢查時間是否合法時間 //開源OSPhP.COM.CN
$timeArr = explode(":", $time);
if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) { $timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59)) //開源OSPhP.COM.CN
return true;
else
return false;
}
return false;
}
function DateDiff($date1, $date2, $unit = "") { //時間比較函數,返回兩個日期相差幾秒、幾分鐘、幾小時或幾天 //開源代碼OSPhP.COm.CN
switch ($unit) {
case 's':
$dividend = 1;
break;
case 'i':
$dividend = 60;
break;
case 'h':
$dividend = 3600;
break;
case 'd':
$dividend = 86400;
break; //oSPHP.COM.CN
default:
$dividend = 86400;
}
$time1 = strtotime($date1);
$time2 = strtotime($date2);
if ($time1 && $time2) $time1 - $time2) / $dividend;
return false;
}
?>
PHP重定向
<?
方法一:header("Location: index.php");
方法二:echo "<scrīpt>window.location ="$PHP_SELF";</scrīpt>"; //PHP開源代碼
方法三:echo "<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">";
?>