Please forgive me, I'm very new to PHP and vB programming.
For a custom page I'm creating, I'm trying to create access permissions based on a user's age.
For a function that I've placed in an external functions_*.php file, I've done what I *think* calculates the logged in user's age, but now I'm not so sure, because my access permissions aren't working. I've borrowed code from memberlist.php to calculate the user's age and return either their age or false.
PHP Code:
function calculate_age($userinfo)
{
global $vbulletin;
if (!isset($userinfo['birthday']))
{
return false;
} else {
$today_year = vbdate('Y', TIMENOW, false, false);
$today_month = vbdate('n', TIMENOW, false, false);
$today_day = vbdate('j', TIMENOW, false, false);
$bday = explode('-', $userinfo['birthday']);
if (date('Y') > $bday[2] AND $bday[2] > 1901 AND $bday[2] != '0000')
{
if ($today_year > $bday[2] AND $bday[2] != '0000')
{
$userinfo['age'] = $today_year - $bday[2];
if ($bday[0] > $today_month)
{
$userinfo['age']--;
}
else if ($bday[0] == $today_month AND $today_day < $bday[1])
{
$userinfo['age']--;
}
}
else
{
return false;
}
if (!$userinfo['age'] AND ($userinfo['age'] < 18))
{
return false;
} else {
return $userinfo['age'];
}
} else {
return false;
}
}
}
Then, after including the function file, to try to calculate permissions based on the calculate_age() function, I used this:
PHP Code:
$age = calculate_age($userinfo);
// access permissions
if ((!is_member_of($vbulletin->userinfo, 5, 6, 7)) OR ((!isset($age)) AND ($age != '$nbsp;')) OR ($age < 18))
{
// give no permission unless in usergroup x, y, or z
print_no_permission();
}
But, no matter what I do, I don't have permission to view this page's content.
Would anyone mind giving me some pointers as to where I'm going wrong?
Thanks!