Tester09 Posted August 17, 2009 Share Posted August 17, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/ Share on other sites More sharing options...
Daniel0 Posted August 17, 2009 Share Posted August 17, 2009 Try checking out date_default_timezone_set. Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900258 Share on other sites More sharing options...
Tester09 Posted August 17, 2009 Author Share Posted August 17, 2009 Try checking out date_default_timezone_set. Thx for the answer! I don't know how to get it to work with my script. Have tried to get it to work for a while but I'm not good at this! Please can u show how to do with my script? Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900278 Share on other sites More sharing options...
Tester09 Posted August 17, 2009 Author Share Posted August 17, 2009 With this code the time is just 20 min wrong; date_default_timezone_set('Europe/Stockholm'); Why? It's so close! Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900404 Share on other sites More sharing options...
PFMaBiSmAd Posted August 18, 2009 Share Posted August 18, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900540 Share on other sites More sharing options...
Tester09 Posted August 18, 2009 Author Share Posted August 18, 2009 This code gives 1h 40 minutes wrong time! Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900686 Share on other sites More sharing options...
Daniel0 Posted August 18, 2009 Share Posted August 18, 2009 As he said, make sure your server's clock is not off. Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-900707 Share on other sites More sharing options...
Tester09 Posted August 18, 2009 Author Share Posted August 18, 2009 I logged in to my webhost but I can't find any setting for server's clock! Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-901257 Share on other sites More sharing options...
Daniel0 Posted August 18, 2009 Share Posted August 18, 2009 Likely you're not the server admin. Contact your host. Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-901260 Share on other sites More sharing options...
Tester09 Posted August 18, 2009 Author Share Posted August 18, 2009 Thanks! The problem was the host like u said! I tried another and it works good [sOLVED] Quote Link to comment https://forums.phpfreaks.com/topic/170692-solved-wrong-time-in-my-user-logger-script/#findComment-901283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.