The php tutorial converts the timestamp to a common date format and the calculation time difference: the default return type is "Minute"
Function trans_time ($ timestamp ){
If ($ timestamp <1) echo 'invalid unix timestamp ';
Else return date ("y-m-d h: I: s", $ timestamp );
}
// Obtain the ip address
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;
}
// Calculation time difference: the default return type is minute"
// $ Old_time can only be a timestamp. $ return_type indicates that h is an hour, and s is a second.
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;
}
}