<?php
function DateAdd($date
$dateArr = explode("
$value[$unit] = $int; //OSPHP
return date("Y
}
function GetWeekDay($date) { //計算出給出的日期是星期幾
$dateArr = explode("
return date("w"
?>
<?
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("
if (is_numeric($dateArr[
}
return false;
}
function check_time($time) { //檢查時間是否合法時間 //開源OSPhP
$timeArr = explode(":"
if (is_numeric($timeArr[
return true;
else
return false;
}
return false;
}
function DateDiff($date
switch ($unit) {
case
$dividend =
break;
case
$dividend =
break;
case
$dividend =
break;
case
$dividend =
break; //oSPHP
default:
$dividend =
}
$time
$time
if ($time
return false;
}
?>
PHP重定向
<?
方法一
方法二
方法三
?>
獲取訪問者浏覽器
<?
function browse_infor()
{
$browser="";$browserver=""; $Browsers =array("Lynx"
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=
{
if (strpos($Agent
{
$browser = $Browsers[$i];
$browserver ="";
}
}
if (ereg("Mozilla"
{
$temp =explode("("
$temp =explode("/"
$browserver =preg_replace("/([d
$browserver = " $browserver"; //OSPHP
$browser = "Netscape Navigator";
}
if (ereg("Mozilla"
{
$temp =explode("("
$temp =explode(" "
$browserver =preg_replace("/([d
$browserver = " $browserver";
$browser = "Opera";
}
if (ereg("Mozilla"
{
$temp = explode("("
$temp = explode(";"
$browserver =preg_replace("/([d
$browserver = " $browserver"; $browser = "Internet Explorer";
}
if ($browser!="")
{
$browseinfo = "$browser$browserver";
}
else
{
$browseinfo = "Unknown";
}
return $browseinfo;
}
//調用方法$browser=browseinfo() ;直接返回結果
?> //oSPHP
<?
function osinfo() {
$os="";
$Agent = $GLOBALS["HTTP_USER_AGENT"];
if (eregi(
$os="Windows
}
elseif (eregi(
$os="Windows ME";
}
elseif (eregi(
$os="Windows
}
elseif (eregi(
$os="Windows
}
elseif (eregi(
$os="Windows NT";
}
elseif (eregi(
$os="Windows XP";
}
elseif (eregi(
}
elseif (eregi(
$os="Linux";
}
elseif (eregi(
$os="Unix"; eregi(
$os="SunOS";
}
elseif (eregi(
}
elseif (eregi(
$os="Macintosh";
}
elseif (eregi(
$os="PowerPC";
}
elseif (eregi(
$os="AIX";
}
elseif (eregi(
$os="HPUX"; //PHP開源代碼
}
elseif (eregi(
$os="NetBSD";
}
elseif (eregi(
$os="BSD";
}
elseif (ereg(
$os="OSF
}
elseif (ereg(
$os="IRIX";
}
elseif (eregi(
$os="FreeBSD"; $os==
return $os;
}
//調用方法$os=os_infor() ;
?>
文件格式類
<?
$mime_types = array(
);
?>
else if (
return
if ((
return (float)(
}
elseif (
}
if (
<?
header("Content
header("Content
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
echo "test
//改動相應文件頭就可以輸出
?>
時間比較問題
舉一個簡單例子說明:比如一個論壇對當天發表的貼子用new圖片標記一下
方法一
<?
//$db
$today=time();
$theDay=date("Y
$newTag=$db
//方法二
$newTag=$db
?>
//提取頁面和浏覽器提交的變量
<?
@extract($_SERVER
@extract($_SESSION
@extract($_POST
@extract($_FILES
@extract($_GET
@extract($_ENV
?>
//寫入文件函數
<?
function writetofile($file_name
$filenum=fopen($file_name
flock($filenum
$file_data=fwrite($filenum
fclose($filenum);
return $file_data;
}
?>
//頁面快速轉向
<?
function turntopage($url="index
print "<html>n<head>n<title>頁面轉向中
print "<meta http
print "<style type="text/css">n<!
print "td { font
print "A {COLOR: #
print "
print "</head>n<body>n";
print "<table width="
print " <tr>n";
print " <td height="
print " </tr>n";
print " <tr>n";
print " <td align="center">n";
print " <table width="
//PHP開源代碼
print " <tr>n";
print " <td height="
print " </tr>n";
print " <tr>n";
print " <td align="center">$info</td>n";
print " </tr>n";
print " <tr>n"; //開源OSPhP
print " <td align="center">n";
print " <a href="$url">如果你的浏覽器不支持自動跳轉
print " </tr>n";
print " </tr>n";
print " </table></td>n";
print " </tr>n";
print " <tr>n";
print " <td height="
print " </tr>n";
print "</table>n";
print "</body>n</html>";
exit;
?>
echo
From:http://tw.wingwit.com/Article/program/PHP/201311/20995.html