ajetrumpet Posted November 24, 2019 Share Posted November 24, 2019 (edited) not sure what to think of this. my code is: $time = date("H:i:s", strtotime("+19 hours")); mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); $stmt = $conn->prepare("INSERT INTO tblTraffic (ip, host, page, date, time) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("sssss", $ip, $host, $page, $date, $time); what I get is in the attached image. as you can see, it returns correct and incorrect values for the same ISP/IP address, but it returns correct values for a google bot. In the past I was using: date("H:i:s"); ....and I was seeing the same results. e.g. - some IP addresses were producing both correct returns and incorrect returns. this correct/incorrect mix was also happening with various google bot /yandex / msn domains as well. what is up with this guys? Edited November 24, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/ Share on other sites More sharing options...
Barand Posted November 24, 2019 Share Posted November 24, 2019 1 hour ago, ajetrumpet said: date("H:i:s", strtotime("+19 hours")); Why +19 hours? Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571851 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 (edited) that originally was working for me when I would visit the site and it would return my own isp domain, which is "client.mchsi.com". but now those damn records are returning something different in the time field! does this have something to do with the fact that I am storing the date field as type "DATE" and the time field as type "TIME" in the MYSQL database? There are other type options for both of these 2 fields, like "DATETIME" and "TIMESTAMP". Edited November 24, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571852 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 (edited) Barand, Can I apply what's on this page: https://tecadmin.net/get-current-date-time-php/ to just getting a date and time separately using what they're doing, for example: $date = new DateTime $date->format('H:i:s') ??? Edited November 24, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571853 Share on other sites More sharing options...
Barand Posted November 24, 2019 Share Posted November 24, 2019 Same thing as what you are currently doing. Both will use the default timezone setting on the php server to give the time value. Your local time is currently UTC -6:00 (ie Central time, 3 weeks ago it was UTC -5:00 when DST applied) What is it on your server? Does your MySQL server have the same timezone setting? Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571854 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 this code: if (date_default_timezone_get()) { echo 'date_default_timezone_set() function return value : ' . date_default_timezone_get() . '<br /><br />'; } if (ini_get('date.timezone')) { echo 'date.timezone() function return value (presumably set in INI file) : ' . ini_get('date.timezone'); } returns this printout: date_default_timezone_set() function return value : UTC date.timezone() function return value (presumably set in INI file) : UTC I've heard that you can also check in godaddy's cPanel UI what time is listed there, but I cannot find that info in mine. Would that also help? Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571855 Share on other sites More sharing options...
Barand Posted November 24, 2019 Share Posted November 24, 2019 (edited) You can override the ini setting by setting it in your code prior to using any date/time functions echo 'Default : ' . date('H:i:s') . '<br>'; // 12:43:34 date_default_timezone_set('America/Chicago'); echo 'Central : ' . date('H:i:s') . '<br>'; // 06:43:34 Edited November 24, 2019 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571857 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 thanks much sir! I ran it with and without "date_default_timezone_set() and it reverted back to original UTC when it was not included. am I to assume that I have to include this date_default....() function in every script I run if I want to capture the proper time? in this case, I am using include() to one file only to capture the report data, so I won't need it more than once this go round, but does the default timezone only get set once per PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571858 Share on other sites More sharing options...
Barand Posted November 24, 2019 Share Posted November 24, 2019 Having run the above code, my phpinfo() in the same script shows However, the output from a second identical script was exactly the same - the default reverted to London time. So the "data.timezone" setting is the one used unless it is set in the script. Running phpinfo() in a separate script shows "London" for both. So, Yes. You would need it every script unless you set it at ini file level. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571859 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 well i don't have access to the INI so I'll have to do it in every script. thank you so much man! Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571860 Share on other sites More sharing options...
Barand Posted November 24, 2019 Share Posted November 24, 2019 If you have a file that is included in every script (such as db connection stuff) put in there Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571861 Share on other sites More sharing options...
ajetrumpet Posted November 24, 2019 Author Share Posted November 24, 2019 (edited) I did. on my webpages I have: <?php include("reporting/pagevisit.php"); ?> and in the pagevisit.php file i put the date_default_timezone_set() function. Edited November 24, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309573-strtotime-returning-many-different-times-based-on-type-of-visitor/#findComment-1571862 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.