Current time: 05-22-2013, 10:40 PM Hello There, Guest! (LoginRegister)


 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[F] Birthday without day [C-StefanT]
06-04-2009, 09:10 PM
Post: #1
[F] Birthday without day [C-StefanT]
If you do not choose the day of your birthday and just the month and the year you get this on the profile page:
Quote:Date of Birth: 00.11.83 (25 years old)
Another user reported that in his forums the date of last day of the month before is shown if he does not choose a day.

Greets,
Michael
-------------
[Image: donation_drive_sig.png]
Visit this user's website Find all posts by this user
06-05-2009, 09:02 AM
Post: #2
RE: Birthday without day
I've been playing this morning with this. It seems, with some date formats, an empty month can interfere too.

The only way I've managed to 100% prevent this bug is this; in ./inc/datahandlers/user.php, find:

PHP Code:
        // Error if a day and month exists, and the birthday day and range is not in range
        
if($birthday['day'] && $birthday['month']) 

Add above:

PHP Code:
        // Pull below 0 to hit error if no input is given
        
if(!$birthday['day'])
        {
            
$birthday['day'] = -1;
        }
        if(!
$birthday['month'])
        {
            
$birthday['month'] = -1;
        } 
Find all posts by this user
06-08-2009, 07:40 AM (This post was last modified: 06-08-2009 07:40 AM by Martin M..)
Post: #3
RE: Birthday without day
If it's already under 1 it would give an invalid birthday though. As it is int validated it would be 0 if no input is given..
Find all posts by this user
06-10-2009, 08:56 AM
Post: #4
RE: Birthday without day
(06-08-2009 07:40 AM)CraKteR Wrote:  If it's already under 1 it would give an invalid birthday though.

No, it doesn't - that's why I made that to pull it under 0. Making it int validated makes it 0, which means no input. MyBB then does this:

PHP Code:
        if($birthday['day'] && $birthday['month'])
        {
            if(
$birthday['day'] < || $birthday['day'] > 31... 

This if statement is where the error is activated, but there is no $birthday['day'], so if the user inputs nothing then the error doesn't get activated. Making it -1 gives $birthday['day'] a value, therefore going through the if statement.

Further reinforcing the fact that I should never eat and develop at the same time, this has the same effect but I think is a better fix:

PHP Code:
        // Error if a day and month exists, and the birthday day and range is not in range
        
if($birthday['day'] && $birthday['month'])
        {
            ...
        }
        else
        {
            
$this->set_error("invalid_birthday");
            return 
false;
        } 

If there isn't a day and month (as required) the error is shown.
Find all posts by this user
06-10-2009, 11:16 AM (This post was last modified: 06-10-2009 11:25 AM by Martin M..)
Post: #5
RE: Birthday without day
(06-10-2009 08:56 AM)Tomm M Wrote:  
(06-08-2009 07:40 AM)CraKteR Wrote:  If it's already under 1 it would give an invalid birthday though.

No, it doesn't - that's why I made that to pull it under 0. Making it int validated makes it 0, which means no input.
Since it is int 0 means 0, not no input.

Why not just delete the line with the check that it's inputted, because it will check that it is above 1 anyways. Since it is intval'ed it will be a number anyways. So no input means 0 which will through an error.

PHP Code:
        if($birthday['day'] && $birthday['month'])
        {
            if(
$birthday['day'] < || $birthday['day'] > 31 || $birthday['month'] < || $birthday['month'] > 12 || ($birthday['month'] == && $birthday['day'] > 29))
            {
                
$this->set_error("invalid_birthday");
                return 
false;
            }

            
// Check if the day actually exists.
            
$months get_bdays($birthday['year']);
            if(
$birthday['day'] > $months[$birthday['month']-1])
            {
                
$this->set_error("invalid_birthday");
                return 
false;
            }
        } 
to
PHP Code:
            if($birthday['day'] < || $birthday['day'] > 31 || $birthday['month'] < || $birthday['month'] > 12 || ($birthday['month'] == && $birthday['day'] > 29))
        {
            
$this->set_error("invalid_birthday");
            return 
false;
        }

        
// Check if the day actually exists.
        
$months get_bdays($birthday['year']);
        if(
$birthday['day'] > $months[$birthday['month']-1])
        {
            
$this->set_error("invalid_birthday");
            return 
false;
        } 

That way it will give an invalid_birthday error because $birthday['day'] is below 1.
That line is unnecessary because it's intval'ed.
Find all posts by this user
06-10-2009, 01:55 PM
Post: #6
RE: Birthday without day
I do believe CraKteR is correct. Intval will return 0 if it is not something that it can convert to an integer. Therefore 0 is the input that it sees, not null or an empty string.
Visit this user's website Find all posts by this user
06-10-2009, 03:28 PM (This post was last modified: 06-10-2009 03:29 PM by Tomm M.)
Post: #7
RE: Birthday without day
I guess "no input" is not really what I'm trying to say... Not trying to insult intelligence, but just to explain what I mean:

PHP Code:
$content ''// No input from the birthday day
$test intval($content); // = '0'
if($test)
{
    echo 
"true";
}
else
{
    echo 
"false";


$content is the birthday['day'], intval'd would mean that this is now 0 ($test). Put through the if statement, it returns false. It's the same that happens in this bug - because $birthday['day'] is 0, it doesn't go through the if statement, and the invalid birthday error isn't returned.
Find all posts by this user
06-10-2009, 03:39 PM (This post was last modified: 06-10-2009 03:39 PM by Martin M..)
Post: #8
RE: Birthday without day
That's why you can remove the
PHP Code:
if($birthday['day'] && $birthday['month']) 
line with ease. It already throws an error if day is < 1 (if that line isn't there), no need for another error message as it would be redundant code.
Find all posts by this user
06-10-2009, 03:46 PM
Post: #9
RE: Birthday without day
(06-10-2009 03:28 PM)Tomm M Wrote:  I guess "no input" is not really what I'm trying to say... Not trying to insult intelligence, but just to explain what I mean:

PHP Code:
$content ''// No input from the birthday day
$test intval($content); // = '0'
if($test)
{
    echo 
"true";
}
else
{
    echo 
"false";


$content is the birthday['day'], intval'd would mean that this is now 0 ($test). Put through the if statement, it returns false. It's the same that happens in this bug - because $birthday['day'] is 0, it doesn't go through the if statement, and the invalid birthday error isn't returned.

Why is why CraKteR's fix of removing that one if statement all together is better.
Visit this user's website Find all posts by this user
06-10-2009, 04:02 PM
Post: #10
RE: Birthday without day
(06-10-2009 03:46 PM)Ryan Gordon Wrote:  Why is why CraKteR's fix of removing that one if statement all together is better.

Like I said... I was just explaining...
Find all posts by this user


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication