Advertisement:

Author Topic: Restrict access to a board based of users age in profile.  (Read 45415 times)

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Restrict access to a board based of users age in profile.
« on: July 23, 2005, 10:57:35 AM »
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.

Code: [Select]
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.
« Last Edit: July 23, 2005, 11:00:04 AM by Ben_S »
Liverpool FC Forum with 14 million+ posts.

Offline Furvert

  • Semi-Newbie
  • *
  • Posts: 81
  • Gender: Male
    • A Tribute To Minerva Mink
Re: Restrict access to a board based of users age in profile.
« Reply #1 on: July 24, 2005, 10:26:22 PM »
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.

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Re: Restrict access to a board based of users age in profile.
« Reply #2 on: July 25, 2005, 04:14:26 AM »
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.

Offline mennou

  • Full Member
  • ***
  • Posts: 507
  • Gender: Male
    • Unitymix,network
Re: Restrict access to a board based of users age in profile.
« Reply #3 on: July 25, 2005, 03:31:30 PM »
where can we  add this code? 

Offline Furvert

  • Semi-Newbie
  • *
  • Posts: 81
  • Gender: Male
    • A Tribute To Minerva Mink
Re: Restrict access to a board based of users age in profile.
« Reply #4 on: July 25, 2005, 05:54:26 PM »
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.

Offline trenchteam

  • Sr. Member
  • ****
  • Posts: 901
  • Gender: Male
    • NO WALLS STANDING
Re: Restrict access to a board based of users age in profile.
« Reply #5 on: July 25, 2005, 08:20:31 PM »
wow, this will be great standard. As I have an area for X rated topics. 

Offline Furvert

  • Semi-Newbie
  • *
  • Posts: 81
  • Gender: Male
    • A Tribute To Minerva Mink
Re: Restrict access to a board based of users age in profile.
« Reply #6 on: July 26, 2005, 06:54:48 PM »
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?

Offline Furvert

  • Semi-Newbie
  • *
  • Posts: 81
  • Gender: Male
    • A Tribute To Minerva Mink
Re: Restrict access to a board based of users age in profile.
« Reply #7 on: July 31, 2005, 04:38:40 AM »
See http://www.simplemachines.org/community/index.php?topic=43818.0
I changed to a new topic for code help

SeaOfSin

  • Guest
Re: Restrict access to a board based of users age in profile.
« Reply #8 on: November 29, 2005, 06:46:30 PM »
Does this work with RC1?  I tried it but nothing happened.

SeaOfSin

  • Guest
Re: Restrict access to a board based of users age in profile.
« Reply #9 on: November 29, 2005, 07:07:52 PM »
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
« Last Edit: November 29, 2005, 08:32:46 PM by Sea Of Sin »

Offline desistyle

  • Jr. Member
  • **
  • Posts: 250
  • Gender: Male
Re: Restrict access to a board based of users age in profile.
« Reply #10 on: December 02, 2005, 12:02:05 AM »
One question where we will be able to add the permssions than in admin panel after we install these codes ?

Offline onijin

  • Jr. Member
  • **
  • Posts: 132
  • Gender: Male
    • Forgotten Garden
Re: Restrict access to a board based of users age in profile.
« Reply #11 on: May 30, 2006, 11:09:37 AM »
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?

Offline Dem0n

  • Full Member
  • ***
  • Posts: 520
  • Gender: Male
  • Word Lyfe!
    • TheTVStop
Re: Restrict access to a board based of users age in profile.
« Reply #12 on: November 23, 2006, 01:51:43 AM »
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?

Offline 05185736

  • Semi-Newbie
  • *
  • Posts: 67
    • The Celeb Venue
Re: Restrict access to a board based of users age in profile.
« Reply #13 on: August 14, 2007, 01:42:22 PM »
was this ever made into a mod??
.::.

Offline statichrist

  • Newbie
  • *
  • Posts: 9
Re: Restrict access to a board based of users age in profile.
« Reply #14 on: September 03, 2007, 11:24:23 PM »
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!
« Last Edit: September 30, 2007, 10:58:50 PM by greyknight17 »

Offline statichrist

  • Newbie
  • *
  • Posts: 9
Re: Restrict access to a board based of users age in profile.
« Reply #15 on: September 03, 2007, 11:54:28 PM »
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.

Offline greyknight17

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,890
  • Gender: Male
    • Kevin's Resource Center
Re: Restrict access to a board based of users age in profile.
« Reply #16 on: September 30, 2007, 11:05:24 PM »
@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.

Offline Hollywood™

  • Semi-Newbie
  • *
  • Posts: 24
  • Gender: Female
  • Kiss me. Love me. <3
    • Miazani Retro Cupcakes
Re: Restrict access to a board based of users age in profile.
« Reply #17 on: November 17, 2007, 07:09:44 AM »
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

Offline Hollywood™

  • Semi-Newbie
  • *
  • Posts: 24
  • Gender: Female
  • Kiss me. Love me. <3
    • Miazani Retro Cupcakes
Re: Restrict access to a board based of users age in profile.
« Reply #18 on: November 17, 2007, 11:26:58 AM »
Bump
People live longer when they mind their own dern business. -Miazani

Offline dave007

  • Semi-Newbie
  • *
  • Posts: 67
    • Deathx
Re: Restrict access to a board based of users age in profile.
« Reply #19 on: November 24, 2007, 07:02:54 AM »
thanks this helped me !