The MU forums have moved to WordPress.org

Solution for server in one country, admin in another timezones (5 posts)

  1. dizzy99
    Member
    Posted 15 years ago #

    Ok i'm writing this quick tip in case anybody faces the same problems i did with UTC (GMT) offset times.

    My server is hosted in Canada but i reside in the UK and my clients (people who will be wanting my blog hostings) equally reside in the UK.

    So heres the deal. Creating a new blog gets Wordpress MU looking at the server time (Canadian time i guess) and setting the offset UTC accordingly (in my case -5). So all my times are off (although funnily enough only for plugins, posts post as GMT).

    In fact i wasn't even aware it had done this to be honest, even modified a Users Online plugin to relect my actual server time and it was only another contributed plugin that started to raise alarm bells (thanks lunabyte :)).

    The situation is easily rectifiable by going to Options and changing the offset to 0 (in my case being smack bang in the middle of GMT). However this is a site wide issue for me and each new blog created has the same issue (not great) and certainly confusing for new to blogging and certainly new to wordpress users.

    Now i'm currently on shared hosting so there's a hope in hell of getting the site time changed just to suit my needs but there is a solution using .htaccess that may be relevant for people who face similar issues in the future.

    First of make sure this really is an issue with your server time and not a rogue plugin setting the wrong times. So lets check what your real server time is.

    To do this create a simple script (call it what you like) and include the following

    '<?php
    echo date ('H:i:s T O');
    ?>'

    Place that in your root directory, run it by calling it from your browser and note the date and more importantly the time. Is it wrong ? Then lets see the solution :)

    in your .htaccess file you can append and load in php values just for your site (handy for us on shared hosting).

    So create a new script (or just append the old one) with the following

    '<?php
    putenv ('TZ=Europe/London');
    ?>'

    What this is doing is setting a timezone (TZ) in this case London, Europe, for my PHP scripts.

    Now we simply add this script anywhere we like (inside or outside of the document root) and call it from .htaccess using the following statement

    php_value auto_prepend_file '/path/to/yournewphpfile.php'

    The path has to be an absolute so something like /home/mysite/html/sitetime.php is needed

    Now ANY php script on your website will have your timezone reported to it without effecting the rest of the server who will likely be on different timezones.

    To find a timezone more appropriate to you check out

    http://www.theprojects.org/dev/zone.txt

    I hope that solution helps people who face a similar issue to what i did.

  2. andrea_r
    Moderator
    Posted 15 years ago #

    "(Canadian time i guess)"

    heh. Canada's a pretty big country last time I checked. :D Right now,, it's anywhere from 2:52pm to 10:22am.

  3. dizzy99
    Member
    Posted 15 years ago #

    Oh no idea :) Being a small country like the UK, we only have to worry about daylight savings :)

  4. Delbert
    Member
    Posted 15 years ago #

    You beauty! This works a treat. Thanks, diz.

  5. neurophyre
    Member
    Posted 14 years ago #

    This does not work for me, specifically, in Site Admin >> Blogs, the date created and last updated will not display the time as anything other than the local server time, which is US/Eastern, despite my setting it to US/Pacific in WHM and the output of 'date' being in PST. I'm thinking there's a bug here but I'm not sure whether it's a WPMU bug or something that should be submitted to Wordpress.

About this Topic

  • Started 15 years ago by dizzy99
  • Latest reply from neurophyre