文档介绍:收藏 PHP 常用函数 shuguang , 10:13 ,代码片段,评论(13) ,引用(0) ,阅读(29978) , Via 本站原创大|中|小<?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" ]; else if(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 ;}?><?php function DateAdd ($date ,$int ,$unit ="d" ){//时间的增加(还可以改进成时分秒都可以增加,有时间再补上) $dateArr =explode ("-" ,$date ); $value [$unit ]=$int ; return date ("Y-m-d" ,mktime (0,0,0,$dateArr [1]+$value [ 'm' ],$dateArr [2]+$value ['d' ],$dateArr [0]+$value ['y' ])); }function GetWeekDay ($date ){//计算出给出的日期是星期几$dateArr =explode ("-" ,$date ); return date ("w" ,mktime (0,0,0,$dateArr [1],$dateArr [2],$date Arr [0])); // }?><?function check_date ($date ){//检查日期是否合法日期$dateArr =explode ("-" ,$date ); if(is_numeric ($dateArr [0])&&is_numeric ($dateArr [1])&& is_numeric ($dateArr [2])) {return checkdate ($dateArr [1],$dateArr [2],$dateArr [0]) ;}return false ; }function check_time ($time ){//检查时间是否合法时间$timeArr =explode (":" ,$time ); if(is_numeric ($timeArr [0])&&is_numeric ($timeArr [1])&& is_numeric ($timeArr [2])) {if(($timeArr [0]>=0&&$timeArr [0]<=23)& &($timeArr [1]>=0&&$timeArr [1]<=59)&&($timeArr [2]> =0&&$timeArr [2]<=59)) return true ;else return false ; }return false ; }function DateDiff ($date1 ,$date2 ,$unit =""){//时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天 switch ($unit ){case 's' :$dividend =1;break; case 'i' :$dividend =60;// break; case 'h' :$dividend =3600 ;break; case 'd' :$dividend =86400 ;break; //开源代码 default: $dividend =86400 ; }$time1 =strtotime ($date1 ); $time2 =strtotime ($date2 ); if($time1 &&$time2 )return (float)( $time1 -$time2 )/$dividend ; return false ; }?>PHP 重定向<?方法一: header ("Location: "