Jump to content

[SOLVED] Wrong time in my user logger script


Tester09

Recommended Posts

Hi!

 

I have an user logger script which logs DATE, IP, HOSTNAME, BROWSER etc.

 

But the time is wrong  :(

 

I have tried with

setlocale(LC_ALL,"swedish");

with bad results. But I really don't know where to put it and what to delete.

 

If you have any resolution please help!

 

 

<?php
    define("DATE_FORMAT","d-m-Y H:i:s");
    define("LOG_FILE","visitors.html");

    $logfileHeader='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Visitors log</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <table cellpadding="0" cellspacing="1">
    <tr><th>DATE</th><th>IP</th><th>HOSTNAME</th><th>BROWSER</th><th>URI</th><th>REFERRER</th><th>USER</th></tr>'."\n";

    $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] != "")) ? $_SERVER['HTTP_USER_AGENT'] : "Unknown";
    $userIp    = (isset($_SERVER['REMOTE_ADDR'])     && ($_SERVER['REMOTE_ADDR'] != ""))     ? $_SERVER['REMOTE_ADDR']     : "Unknown";
    $refferer  = (isset($_SERVER['HTTP_REFERER'])    && ($_SERVER['HTTP_REFERER'] != ""))    ? $_SERVER['HTTP_REFERER']    : "Unknown";
    $uri       = (isset($_SERVER['REQUEST_URI'])     && ($_SERVER['REQUEST_URI'] != ""))     ? $_SERVER['REQUEST_URI']     : "Unknown";
$username = (isset($_SESSION['userName'])     && ($_SESSION['userName'] != ""))     ? $_SESSION['userName']     : "Unknown";
    
    $hostName   = gethostbyaddr($userIp);
    $actualTime = date(DATE_FORMAT);

    $logEntry = "     <tr><td>$actualTime</td><td>$userIp</td><td>$hostName</td><td>$userAgent</td><td>$uri</td><td>$refferer</td><td>$username</td></tr>\n";

    if (!file_exists(LOG_FILE)) {
        $logFile = fopen(LOG_FILE,"w");
        fwrite($logFile, $logfileHeader);
    }
    else {
        $logFile = fopen(LOG_FILE,"a");
    }

    fwrite($logFile,$logEntry);
    fclose($logFile);
?>

I'm pretty sure (but could be wrong) that there are no Europe timezones based on 20 minutes past the hour. Your server's clock is probably not set correctly. Does the following give the correct minutes -

 

echo gmdate("d-m-Y H:i:s");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.