MyBB Community Forums

Full Version: [B] birthday in user profile wrong
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
on our installation of 1.4.1 the birthday for users born before 1970 was displayed wrongly. Day and month were wrong. The reason seems to be an error in member.php. There are two parallel attempts to correct the 1970-problem, one is not good. The original code is:
	if($memprofile['birthday'])
	{
		$membday = explode("-", $memprofile['birthday']);
		
		if($memprofile['birthdayprivacy'] != 'none')
		{
			if($membday[2])
			{
				$lang->membdayage = $lang->sprintf($lang->membdayage, get_age($memprofile['birthday']));
				
				if($membday[2] >= 1970)
				{
					$w_day = get_weekday($membday[1], $membday[0], $membday[2]);
					$membday = format_bdays($mybb->settings['dateformat'], $membday[1], $membday[0], $membday[2], $w_day);
				}
				else
				{
					$bdayformat = fix_mktime($mybb->settings['dateformat'], $membday[2]);
					$membday = mktime(0, 0, 0, $membday[1], $membday[0], $membday[2]);
					$membday = date($bdayformat, $membday);
				}
				$membdayage = $lang->membdayage;
			}
			else
			{
				$membday = mktime(0, 0, 0, $membday[1], $membday[0], 0);
				$membday = date("F j", $membday);
				$membdayage = '';
			}
		}
		
		if($memprofile['birthdayprivacy'] == 'age')
		{
			$membday = $lang->birthdayhidden;
		}
		else if($memprofile['birthdayprivacy'] == 'none')
		{
			$membday = $lang->birthdayhidden;
			$membdayage = '';
		}
	}
	else
	{
		$membday = $lang->not_specified;
		$membdayage = '';
	}

This bit here causes the trouble, the year is passed to mktime. After that the year is reinserted by the $bdayformat-hack. But then the $membday-timestamp already has the wrong month and day.
				else
				{
					$bdayformat = fix_mktime($mybb->settings['dateformat'], $membday[2]);
					$membday = mktime(0, 0, 0, $membday[1], $membday[0], $membday[2]);
					$membday = date($bdayformat, $membday);
				}

I took out the whole discrimnation between before and after 1970 because the functions called from function.php already deal with the issue and it works fine here. This is the fixed code:
	if($memprofile['birthday'])
	{
		$membday = explode("-", $memprofile['birthday']);
		
		if($memprofile['birthdayprivacy'] != 'none')
		{
			if($membday[2])
			{
				$lang->membdayage = $lang->sprintf($lang->membdayage, get_age($memprofile['birthday']));
				
				$w_day = get_weekday($membday[1], $membday[0], $membday[2]);
				$membday = format_bdays($mybb->settings['dateformat'], $membday[1], $membday[0], $membday[2], $w_day);
				$membdayage = $lang->membdayage;
			}
			else
			{
				$membday = mktime(0, 0, 0, $membday[1], $membday[0], 0);
				$membday = date("F j", $membday);
				$membdayage = '';
			}
		}
		
		if($memprofile['birthdayprivacy'] == 'age')
		{
			$membday = $lang->birthdayhidden;
		}
		else if($memprofile['birthdayprivacy'] == 'none')
		{
			$membday = $lang->birthdayhidden;
			$membdayage = '';
		}
	}
	else
	{
		$membday = $lang->not_specified;
		$membdayage = '';
	}

Can someone please check, confirm or correct me? Thanks.

Zakkinen
Hi,

I just setup a test installation with a test user setup for 1968, and it works perfectly fine.

Ryan
All right, I was in a hurry when I wrote the first entry. It still holds for us. We have myBB on a provider host, Linux I assume, with php 4.4.8 and mySQL 4.1.22. Don't think the SQL has anything to do with it.

It works perfectly well with the fix I described, but gives the wrong values for day and month without, but only for users born before 1970.

Additionally I set up a test system with Apache, PHP 5.2.6 and MySQL 5.0.67 (on a Windows System). It works perfectly well with my changes. But it does so as well without.

So my conclusion is:
a) must be a problem with PHP 4.x
b) the lines I removed aren't neccessary in any case, they are not needed on PHP 5.x and they produce a wrong result on PHP 4.x

Cheers
Zakkinen
Hi,

You should upgrade to PHP 5 anyway. PHP 4 is not supported by the PHP group anymore.
Did that. But I guess having a look at the code is worthwhile. No good having superfluous lines in the code. And the functions seem to do all the necessary corrections anyway. This is imho not needed at all:
                    $bdayformat = fix_mktime($mybb->settings['dateformat'], $membday[2]);
                    $membday = mktime(0, 0, 0, $membday[1], $membday[0], $membday[2]);
                    $membday = date($bdayformat, $membday);