How to Get WP-SlimStat to Recognize Your Local Timezone

So, I use the wp-slimstat for purposes of tracking some statistics on this website, and I am lovin’ it although it is largely unsupported. I’d like to present a humble solution to a Local Timezone problem I’ve been having.

Before HackThe problem: Wp-Slimstat’s time would be offset by a few hours, as it would only grab the server’s time. The problem is my server is in Los Angeles, and I am in Toronto. Result? The time for all the stats would be off by 3 hours. Bleh. :(

Well, there is a hack, if your Server has PHP5 (if you want to check out what version your server has, go here)

The Solution: Use the date_default_timezone_set function!
Basically, this will set a default timezone for a given script if you give it the proper location from where you are, rather than displaying the server’s default timezone. Luckily Wp-SlimStat is a single script — wp-slimstat.php — and so adding a single line of code with this function should affect the whole statistics package (and it did for me!)

This particular function requires a single argument, and that is the location.
It just so happens that there is an index for where you can find your own location, and how format that Argument.

For example, I am in Toronto, Canada. Therefore, I added “America/Toronto” to the arguments, so it ended up being:

date_default_timezone_set (”America/Toronto”);

Here’s how you can do it too:

Step 1. Open up wp-slimstat.php in your favourite text editor (I use PSPad).
Step 2. Find somewhere early in the plugin to pop in the script. I think line 30 should be fine.

Before Code Inserted

Step 3. Insert your line of code (I also included a Comment).

After Code Insertion

Step 4. Save, upload, and there should be an automatic change!

After the Hack

Well, I hope that was pretty self-explanatory.

This was sort of crucial for me, as I often post after-midnight local time — and the stats would show that people would be arriving BEFORE my post. It would drive me crazy! Anyway, enjoy! And as always, support the author (particularly if you read Italian), who is doin’ some great work. Lavoro grande!

3 Comments

  1. Posted October 26, 2006 at 3:32 am | Permalink

    Good! It works fine, thanks for your sharing. :)

  2. Tony
    Posted October 26, 2006 at 7:25 am | Permalink

    I’m glad you found it useful! :)
    Thanks for stopping by.

  3. Posted December 14, 2007 at 1:47 pm | Permalink

    hi thanks for sharing! nice tweak, but i have other sites under PHP4 any suggestions?

2 Trackbacks

  1. By Slimstat set local time at Cun Zhang’s Blog on March 12, 2008 at 11:02 am

    [...] my wp.But I find it display this server time,not my local time. I google and find the answer from Deep Jive’s site. I put a line of code (as follow) into wp-slimstat.php,then it works fine. Thanks for Deep [...]

  2. By Recent Links Tagged With "slimstat" - JabberTags on September 8, 2008 at 11:50 pm

    [...] public links >> slimstat How to Get WP-SlimStat to Recognize Your Local Timezone Saved by gisiger on Mon 08-9-2008 かんのものおき " Wp-SlimStat-Ex アクセス解析 [...]

Post a Comment

Your email is never published nor shared.

Powered by WP Hashcash