Page 1 of 1

$userdata['user_level']

Posted: Mon Nov 22, 2010 11:24 am
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 $)

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 11:36 am
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

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 12:46 pm
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

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 12:47 pm
by updown
Leon90 wrote:user_level
exactly, a 'user_level' value doesn't exist in an original installation

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 12:51 pm
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?

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:08 pm
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 :?

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:10 pm
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
}

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:23 pm
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 ;)

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:37 pm
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-) )

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:43 pm
by RMcGirr83
auth class documents for future reference.

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:43 pm
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.

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 1:50 pm
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.

Re: $userdata['user_level']

Posted: Mon Nov 22, 2010 2:23 pm
by Leon90
Ok, thanks everyone

i think i figured it out :D

:mrgreen: