Jump to content

strtotime() returning many different times based on type of visitor


ajetrumpet

Recommended Posts

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?

time inconsistency.jpg

Edited by ajetrumpet
Link to comment
Share on other sites

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 by ajetrumpet
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Having run the above code, my phpinfo() in the same script shows

image.png.b2564397eeff0472ee131e42d8438766.png

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.

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.