Time zones in php

Hi

I’ve been reading up about setting time zones and all but im still quite confused.

On my site i want users to be able to set their timezone on their account. Firstly, what should i store the different options as in my database and then how do i go about setting the right time zone when a user logs in?

At the moment while i’ve been working on my site i just have

date_default_timezone_set('Africa/Johannesburg');

at the beginning of my page and this seems to be giving me the correct time throughout the site.
Should i now pull the timezone value from the database that the user has selected and use this same function or is there a better way? And then is this timezone only implemented when i use the date() function to format my date/time when getting date/times from a database?
Also, i’ve noticed that when storing dates in the database using the CURRENT_TIMESTAMP as default of the field in a table, it uses my timezone (GMT+2) or is mysql automatically setting this?

Either way, what is the best way to go about this?

Thanks!

Your server is controlling the date() function as it is being run locally and the CURRENT_TIMESTAMP as that is as well.
If you want it to be taken from the local user using your site you will need it to run from the local machine and collected before sending back to the server.

I believe all server requests like that are local to the timezone they are in.

I think there is a way to set the server’s request to be according to another timezone each time but then you have to pass it to the script aswell.

Anybody know any more on this one?

Definitely don’t change PHP’s timezone – that will cause your database to use that timezone too and then everything will start exploding.

I made a thread on this a week ago that you might want to check out. I posted the code I use.