$userdata['user_level']

Discussion forum for MOD Writers regarding MOD Development.
Locked
Leon90
Registered User
Posts: 5
Joined: Mon Nov 08, 2010 11:19 pm

$userdata['user_level']

Post by Leon90 »

Support Request Template
What version of phpBB are you using? phpBB 3.0.7
What is your board's URL? http://elcclan.impulzstudios.com/forums
Who do you host your board with? No answer given
How did you install your board? I used the download package from phpBB.com
Is your board a fresh install or a conversion? Fresh Install
Do you have any MODs installed? No
Is registration required to reproduce this issue? No
What styles do you currently have installed? Standard
What language(s) is your board currently using? English
Which database type/version are you using? MySQL 5
What is your level of experience? Comfortable with PHP and phpBB

When did your problem begin?
Im trying to get an external website to link with the forums, and so use the $userdata from the forums so the admins could use the same login to get to the admin section of the page too.

Please describe your problem.
The only problem is when i use this code:

Code: Select all

    define('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../forums/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
    

Code: Select all

    $userdata = $user->data;
    if($userdata['session_logged_in'] && $userdata['user_level'] == ADMIN)
    
The $userdata seems to work fine, since session_logged_in works
also allot of other functions from the $userdata seem to work except from the user_level part.
Im pretty sure im logged in as an admin on the board, but the $userdata['user_level'] always seems to stay empty
dont know what i am doing wrong though

Hope someone can help me out here
thanks in advance
Generated by SRT Generator ($Rev: 4502 $)
User avatar
Marshalrusty
Project Manager
Project Manager
Posts: 29298
Joined: Mon Nov 22, 2004 10:45 pm
Location: New York City
Name: Yuriy Rusko
Contact:

Re: $userdata['user_level']

Post by Marshalrusty »

Hello,

Your problem is that ADMIN is not a defined constant. Choose from the following:

Code: Select all

define('USER_NORMAL', 0);
define('USER_INACTIVE', 1);
define('USER_IGNORE', 2);
define('USER_FOUNDER', 3);
In this case, you probably want USER_FOUNDER
Have comments/praise/complaints/suggestions? Please feel free to PM me.

Need private help? Hire me for all your phpBB and web development needs
Leon90
Registered User
Posts: 5
Joined: Mon Nov 08, 2010 11:19 pm

Re: $userdata['user_level']

Post by Leon90 »

So if i understand correctly i have to use $userdata['user_type']
instead of the user_level, because when i echo teh $userdata['user_type']
it echo's out the number 3

so then i have to use?:

Code: Select all

$userdata['user_type'] == '3'
thanks for the fast reply btw
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: $userdata['user_level']

Post by updown »

Leon90 wrote:user_level
exactly, a 'user_level' value doesn't exist in an original installation
Leon90
Registered User
Posts: 5
Joined: Mon Nov 08, 2010 11:19 pm

Re: $userdata['user_level']

Post by Leon90 »

updown wrote:
Leon90 wrote:user_level
exactly, a 'user_level' value doesn't exist in an original installation
Though i see everyone using user_level == ADMIN so thats why i guessed it should work :D

will try the user_type thingie

do i have to re-define the founder like in the previous reply?
User avatar
RMcGirr83
Former Team Member
Posts: 21696
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: $userdata['user_level']

Post by RMcGirr83 »

Leon90 wrote:
updown wrote:
Leon90 wrote:user_level
exactly, a 'user_level' value doesn't exist in an original installation
Though i see everyone using user_level == ADMIN so thats why i guessed it should work :D

will try the user_type thingie

do i have to re-define the founder like in the previous reply?
User_level == ADMIN is from phpBB version 2.x, if I recall correctly, so your code (if you want only Founder access) should be

Code: Select all

if ($userdata['user_level'] == USER_FOUNDER)
{
   whatever in here
}
I am interested though why you are creating a new variable ($userdata) when $userdata = $user->data :?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: $userdata['user_level']

Post by updown »

Leon90 wrote:
updown wrote:
Leon90 wrote:user_level
exactly, a 'user_level' value doesn't exist in an original installation
Though i see everyone using user_level == ADMIN so thats why i guessed it should work :D
that's old stuff from phbBB 2.x ;)

phpBB 3.x uses $auth to check for individual admin-rights, or user_type for FOUNDER-Status.

Code: Select all

if ($userdata['user_type'] == USER_FOUNDER)
{
   whatever in here
}
Leon90
Registered User
Posts: 5
Joined: Mon Nov 08, 2010 11:19 pm

Re: $userdata['user_level']

Post by Leon90 »

First off thanks for the help, the user_type seems to work.
This is my code right now

Code: Select all

if($userdata['user_type'] == 3 && $userdata['is_registered'])
Found a big list of userdata stuff right here
http://www.phpbb.com/kb/article/phpbb3- ... tegration/

came across this: session_admin - 0
can i use that or do i have to stick with founder, because i dont want to make everyone a founder :D

and i hope the use of 'is_registered' is ok for checking if they are logged in. (used 'session_logged_in' before)

ow yeah and i made the $userdata from $user->data because i found it easier to type ;)
updown
Registered User
Posts: 542
Joined: Sat Jan 05, 2008 6:53 am

Re: $userdata['user_level']

Post by updown »

then use

Code: Select all

if ($auth->acl_get('a_'))
{

}
checks if current user has any kind of admin-Rights

(If you still want to use a check for Founder-Status, you don't have to check if the user is registered - guest and bots can't be founders ;-). Also you should prefer using the variable USER_FOUNDER instead of the number, helps avoiding mistakes 8-) )
User avatar
RMcGirr83
Former Team Member
Posts: 21696
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: $userdata['user_level']

Post by RMcGirr83 »

auth class documents for future reference.
Last edited by RMcGirr83 on Mon Nov 22, 2010 1:43 pm, edited 1 time in total.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
User avatar
3Di
Former Team Member
Posts: 16053
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano 🇮🇹 - Frankfurt 🇩🇪
Name: Marco
Contact:

Re: $userdata['user_level']

Post by 3Di »

yeah and i made the $userdata from $user->data because i found it easier to type
copy/paste instead?
updown wrote:Also you should prefer using the variable USER_FOUNDER instead of the number
yeah, no magic numbers.
To request support for our extensions you can also contact me here: phpBB Studio

Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
🚀 Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
tbackoff
Former Team Member
Posts: 7064
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: $userdata['user_level']

Post by tbackoff »

Leon90 wrote: When did your problem begin?
Im trying to get an external website to link with the forums
Hello,

Since this deals with custom coding and is not part of a vanilla phpBB, I have moved your topic to the MOD Writers Discussion forum.
Flying is the second best thrill to cheerleaders; being caught is the first.
Leon90
Registered User
Posts: 5
Joined: Mon Nov 08, 2010 11:19 pm

Re: $userdata['user_level']

Post by Leon90 »

Ok, thanks everyone

i think i figured it out :D

:mrgreen:
Locked

Return to “[3.0.x] MOD Writers Discussion”