php tutorial conversion timestamp for the common date format and calculation of time difference: the default return type is "minutes"
function trans_time ($ timestamp) {
if ($ timestamp <1) echo 'invalid unix timestamp';
else return date ("ymd 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 the time difference: the default return type is "minutes"
// $ old_time can only be a timestamp, $ return_type is h is hour, s is 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;
}
}