Search code examples
phpfunctiontimelocalsmf

PHP get user's local time (in SMF)


I know php isn't very handy when it gets to fetching local time because it requires the user to have a cookie with the corresponding offset. I'm looking to get a value for the user's time using SMF (which should already have this information in the databse). I couldn't find out how to do this by using smf's site, so I'm asking here.

If you're wondering why, it's because I have 2 themes a "day" and a "night" theme. I want the night one to be displayed if the time falls between the two corresponding times.

BTW you can see these themes here: http://hetoan2.com/forum and night: http://hetoan2.com/forum?v=night

thanks for your help :D


Solution

  • Easily the best way would just be to use the Date() method in JavaScript. This gives you the date and time of the user's machine.

    If, however, you only want to use php (for whatever reason), you could use a geolocation tool like IPInfoDB to get the users current location and then use date_default_timezone_set to set the timezone of the user to the timezone of your server, and then get the date that way.