Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Server time issues

Aloittaja KidCactus, syyskuu 20, 2011, 08:54:44 AP

« edellinen - seuraava »

KidCactus

Can someone please explain this to me:

The time is now 14:47 in Sweden. SMF sees the time as:

LainaaTime information about the Server

Current Servertime: September 20, 2011 13:47:38
Calculated UTC Time: September 20, 2011 12:47:38

If I put in a random date('G') in the SMF code, it returns 13. Which it should, when the server time is 13:47. But, if I put date('G') in a simple empty PHP file outside SMF (but still in the same folder on the server), I get 14.

So for some reason, my SMF installation seems to think the server time is one hour less that it should be (and is according to my PHP test file). Any ideas why it's like this?

This wouldn't be a problem really, but I have made a rotating header that changes every day according to which day is, and at the moment it's not changed until after 01:00, when it really should be changed at 00:00.

Illori

in 1.1.1* there is no way to set the overall time offset, but in your profile -> look and layout preferences you can set your own time.

KidCactus

Thanks for the quick reply, but I don't think you understand my issue. :)

If I put this in index.template.php:

print date('G');

...it returns 13 when the time really is 14:xx.

If I put the exact same code in its own PHP file, and put it in the same folder as my index file, it returns 14 (as it should) when I run it.

My PHP test file:

<?php

print date('G');

?>


Shouldn't I get 14 with this code in the index.template.php file too? :o

Illori

and if you do what i suggest is the time shown correctly? that should be good enough for me ;) otherwise i would suggest you ask your host about this as i dont think it is an smf issue.

KidCactus

#4
If I do what you suggest, nothing changes — date('G') in the template file still shows one hour off.

I was about to e-mail my host about this, but then I realized that it's only when I put the code into the SMF template file that I get the wrong time. Very odd, I must say.

It feels like the source file calling index.template.php must be screwing with my time, can't think of anything else. Which file would that be?

Btw, I also have a WordPress blog installed on a subdomain of my domain, and if I put the same code in any of its template files, it returns the correct value.

Edit: This also occurs on a completely new SMF installation, just tried it.

Edit 2: If I put the code in ./index.php, it actually does show me the correct value! :o I really don't get how this can be different depending on from which PHP file in the SMF installation this is called.

KidCactus

#5
print date('G'); in ./index.php (correct value):



print date('G'); in ./Themes/default/index.template.php (wrong value):



Can someone confirm this behavior?

Edit: This most certainly is a SMF issue; I've now confirmed the same behavior on two different hosts.

Edit 2: I think I've come up with a workaround, using date('G', $timestamp = (time()+3600)) where I need it to be correct.

Joker™

I made a test on my local server with different time zones and was unable to replicate the issue.

I've even changed the date.timezone in php.ini but still can't produce the issue you have described.

Also SMF works in layer system in which the templates are loaded using load.php which is called in index.php of your forum.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

MrPhil

If you created the site originally on PHP 5.1 or higher, SMF should have what it thinks is the correct timezone stored in the database somewhere. IIRC, the settings table (?) "default_timezone" or something like that. If it was generated automatically by the SMF installation, it's probably /etc/GMT-n, where 'n' is one hour off (and doesn't reflect DST/Summer Time). If so, use phpMyAdmin to change it to Europe/Stockholm, or whatever the correct code is for you.

If that's not it, you'll have to dig around to see what timezone is being used by PHP. What is your PHP level, by the way? Do you have an entry in php.ini, or environment variable, or something else?

KidCactus

Lainaus käyttäjältä: MrPhil - syyskuu 20, 2011, 04:11:34 IP
If you created the site originally on PHP 5.1 or higher, SMF should have what it thinks is the correct timezone stored in the database somewhere. IIRC, the settings table (?) "default_timezone" or something like that. If it was generated automatically by the SMF installation, it's probably /etc/GMT-n, where 'n' is one hour off (and doesn't reflect DST/Summer Time). If so, use phpMyAdmin to change it to Europe/Stockholm, or whatever the correct code is for you.
Your were spot on, this solved the whole issue. Thank you so much! :)

MrPhil

Lainaus käyttäjältä: KidCactus - syyskuu 21, 2011, 05:10:28 AP
Your were spot on
Oh no, here comes the K2R Spot Remover! Ayyyyyyyyyye!

Glad to have helped...

Advertisement: