Restricting forum access with rules, roles and forum access

It's a little bit premature asking for help already since I haven't really tried to code this fully - but I'm hoping someone might save me hours of frustration (since I don't have any php experience).

I'm trying to setup a forum that provides restricted acces based on the age of the user. Some forums need to be accessible only by users under 18 and some forums may contain adult content that should only be accessible by users over 18.

I started by setting up 2 roles: major (over 18s) and minor (under 18s). I've then used the forum access module to limit what forums can be accessed by which role.

Now to automate the role assignment, I'm trying to use rules to evaluate the users age each time he/she logs on, and then to assign/unassign the role. It's easy to assign roles/unassign roles using rules, but I'm having trouble with the php code that evaluates the users age.

I've found php code to return the age, but I've found it easier to just use the birthdays module (I also need some of the other functionality) to get the age.

As said before, I have NO php experience, so the code below is the best I can do. Any help would be appreciated (just to determine the users age from the birthday module and return a true or false that can be assessed.

if ($user['values'][birthdays-age'] < 18)
{
return TRUE;
}
return FALSE;

I'm sure it shows that I'm a real newbie to php :-)

Groups:
Login to post comments

Solved

Drew Patrick - Wed, 2009-06-24 09:50

Never mind - I seem to have worked it out (using date_of_birth instead of the birthday module):

$year_diff = date("Y") - ($account->profile_date_of_birth['year']);
$month_diff = date("m") - ($account->profile_date_of_birth['month']);
$day_diff = date("d") - ($account->profile_date_of_birth['day']);

if ($month_diff < 0)
{
$year_diff--;
}
elseif ($month_diff == 0 && $day_diff < 0)
{
$year_diff--;
}

if ($year_diff < 18)
{
return TRUE;
}
return FALSE;