News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Restrict access to a board based of users age in profile.

Started by Ben_S, July 23, 2005, 10:57:35 AM

Previous topic - Next topic

Ben_S

This will allow you to prevent people under a certain age from accessing a certain board. Bear in mind it is only basic and probably not coded to well as I cobbled it together in 5 mins. It will not prevent people from viewing posts in a certain board by using the recent posts features or search.

Someday I may come back to it and turn it into a proper mod with an admin interface and correct the limitations.

Sources/Load.php

Find
'time_offset' => empty($user_settings['timeOffset']) ? 0 : $user_settings['timeOffset'],

Add After
                'birthdate' => empty($user_settings['birthdate']) ? 0 : $user_settings['birthdate'],


Sources/MessageIndex.php

Find
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_messageindex';
else
loadTemplate('MessageIndex');


Add After
    //check their age for acess to a certain board
    if ($board == '20') // Change 20 to the ID_BOARD you want to restrict access to.
    {
        if (!empty($user_info['birthdate']))
{
            if ($user_info['birthdate'] != '0000-00-00')
            {
list ($birth_year, $birth_month, $birth_day) = sscanf($user_info['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$user_info += array(
'age' => empty($birth_year) ? $txt[470] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
                'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
);
            }
            else
            {
                $user_info['age'] = '0';
            }
}
       
        if ((@$user_info['age'] < '18') && (!$user_info['is_admin']))
            fatal_error('Sorry, you must be at least 18 to access this board', false);
    }

Sources/Display.php

Find
// Load the proper template and/or sub template.
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_display';
else
loadTemplate('Display');

Add After
    //check their age for tickets board
    if ($board == '20')
    {
        if (!empty($user_info['birthdate']))
{
            if ($user_info['birthdate'] != '0000-00-00')
            {
list ($birth_year, $birth_month, $birth_day) = sscanf($user_info['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$user_info += array(
'age' => empty($birth_year) ? $txt[470] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
                'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
);
            }
            else
            {
                $user_info['age'] = '0';
            }
}
       
        if ((@$user_info['age'] < '18') && (!$user_info['is_admin']))
            fatal_error('Sorry, you must be at least 18 to access this board', false);
    }


Theres also probably a load of stuff in there that isn't required, if anyone want's to clean it up, feel free.
Liverpool FC Forum with 14 million+ posts.

Furvert

Thanks for pointing this out, I may try it.

Yup, that type of code can work.

It would be nicer as a permission, so I will continue to look into adding that. I have multiple boards with age restricts so it would get messy to code specifics for it.

Ben_S

It was something I did quick as I needed something similar for my board, I may come back to it and use the permissions system and turn it into a mod.
Liverpool FC Forum with 14 million+ posts.

mennou


Furvert

Permissions would be the best and more compatible for everyone.
I will still look into how to do that but I cant currently edit my database so its a bit harder to do.
I think I recall some tutorials here that may mention some of this, as too which files need to be moded.

trenchteam

wow, this will be great standard. As I have an area for X rated topics. 

Furvert

It appears that a simple mod to permissions would allow this.
http://www.simplemachines.org/community/index.php?topic=19136.0 covers permissions briefly

What is needed is a setting for age>=xxx required, thus a permission variable of 'MinAge' needs to be added. This would need to be put in 'ManagePermissions.php' and added to the database with default of 0. The code to use it would need to declare undefined birthday as age -1 in that case, so perhaps a better default is needed.

I have not yet found where the use code is needed so that is blends seamlessly with other permissions. But it should be possible to do so. The same place that determines membergroup access to boards should work in which case the forbidden boards do not show.

edit- $user_info[query_see_board] is where it is needed, now to find it. 'Security.php' may have it?

Furvert


SeaOfSin

Does this work with RC1?  I tried it but nothing happened.

SeaOfSin

#9
OK, I sorted that problem but how can I do it for multiple boards?

I'm doing well today. Solved that too.  Just use the following

    if ($board == '2' || $board == '36' || $board == '20' || $board == '35' || $board == '36' || $board == '72')

Sea Of Sin

desistyle

One question where we will be able to add the permssions than in admin panel after we install these codes ?

onijin

works good.  However, if they don't input an age, they can access the board.  Is there a way to include the <18 with no birthdate given?

Dem0n

how exactly does this restrict a users age? I've installed it and have no idea what I'm supposed to be looking for. How do I restrict access?

05185736

.::.

statichrist

#14
If anyone is willing to work with me on making this a mod (since the owner has seemingly not replied for 2 years) I will be glad to! I have very little experience, but wouldn't mind learning and also helping someone else do this!
email edited out

Thanks!

statichrist

I've begun doing the very basicsc of making this a real modification. Please, if anyone is interested, let me know. I'm not sur what the next steps are.

greyknight17

@statichrist: This is a public forum (spambots crawl here) and I don't recommend posting your email here...edited out ;)

Were you able to get this working somehow? If so, there is help here on how to make it a mod if you know what code edits are needed. If you still need help with this, you can ask in the SMF Coding Discussion for more help on this possible mod.

Hollywood™

Where do you put the codes? Does this work for 1.1.4?
And does anyone have any new updates on whether this became a Mod or not?
People live longer when they mind their own dern business. -Miazani

Hollywood™

People live longer when they mind their own dern business. -Miazani


Advertisement: