MyBB Community Forums

Full Version: Need creative solution to time issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, I'm an admin on a forum running MyBB that is having issues with the forum time. We have an issue with the server host where the server's time, and therefore our forum time, is getting messed up every so often. Unfortunately, the main admin for the forum, who has not given other admins access or contact with the server owner, is often absent for weeks at a time.

We're in the process of getting this situation rectified, but in the meantime, I want our forum's large and active userbase to continue to thrive. The issue of forum time has been a significant issue, in regards to keeping posts in proper order and all.

So, does anyone know a creative workaround I can use to temporarily change the forum clock, so that new posts line up in their proper order? I have access to the admin portal, as well as FTP to the forum's files, so I should be able to do most things (except fix the server issues. Angry )
Does it jump into the future or into the past?

Jumps into the past could be prevented.

inc/init.php has this code: define("TIME_NOW", time());

And everything else uses TIME_NOW for the time.

So you could do instead:

$t = time();
$last_known_time = filemtime(MYBB_ROOT.'/cache/LAST_KNOWN_TIME'); // load last known time
if($t < $last_known_time)
{
    // LOL past
    $t = $last_known_time + 1;
}
touch(MYBB_ROOT.'/cache/LAST_KNOWN_TIME', $t, $t); // store last known time
define("TIME_NOW", $t);

At that point, as long as the server's time is wrong, the forum's time will go at one second per request. The time will still be wrong, but at least the posts will stay in the right order and everything.

However if the server time goes in the future, your forum will be stuck in the future. So this will only works if the server sometimes believes it's 1999 or something.

You'll have to create a file cache/LAST_KNOWN_TIME and chmod it writable (666 or whatever you like). If you have an FTP client which is able to update timestamps of a file, you could try that to sync the real time from client to server.

Note this will only affect code that actually uses the TIME_NOW define. That should be almost all of MyBB, but may not be true for its plugins.
The clock goes back in time, usually anywhere from 5-8 hours. So it looks like this could be helpful, I'll try it out and see how it works. Thanks!
Note I made some edits to my post. Good luck! Let me know if this works, as I haven't actually tried it.

more edits, lol typos