PHP Tutorial convert timestamp to commonly used date format with calculated time difference: The default return type is "minutes"
function Trans_time ($timestamp) {
if ($timestamp < 1) echo ' Invalid Unix timestamp ';
else return date ("Y-m-d h:i:s", $timestamp);
}
Get IP
function Get_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;
}
Calculate time difference: The default return type is "minutes"
$old _time can only be timestamp, $return _type to H is hour, s is seconds
function Timelag ($old _time, $return _type= ' m ') {
if ($old _time < 1) {
echo ' Invalid Unix timestamp ';
}else{
Switch ($return _type) {
Case ' H ':
$type = 3600; Break
Case ' m ':
$type = 60; Break
Case ' s ':
$type = 1; Break
Case ':
$type = 60; Break
}
$dif = Round (Time ()-$old _time)/$type);
return $dif;
}
}
http://www.bkjia.com/PHPjc/632349.html www.bkjia.com true http://www.bkjia.com/PHPjc/632349.html techarticle PHP Tutorial convert timestamp to commonly used date format with calculated time difference: The default return type is minute function Trans_time ($timestamp) {if ($timestamp 1) echo ' Invalid Unix timestamp ';