vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Check persmissions using PHP? (https://vborg.vbsupport.ru/showthread.php?t=208209)

CEMarijn 03-13-2009 01:38 PM

Check persmissions using PHP?
 
Hi all,

I have a small question concerning custom php code. I want to include a link to a php file on my forum that everyone can see. This php script should then check if the user is logged in. If he is, he is redirected to the content. If not, he gets a message that he does not have permission.

I found the following code (this example should only work for admins), but that does not work.

<?php
if ($vbulletin->userinfo['usergroupid'] == '6' )
{
echo "Welcome to the premium section!";
} else {
echo "You do not have permission for this page"; }
?>

I outputted the usergroupid variable, but it is just empty. I am completely new to vbulletin, so this might be a very noobish question. But please help :) Thanks in advance!

Lynne 03-13-2009 02:37 PM

You need to include global.php in the page in order to check for permissions. See this - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. Then you can check for usergroups by doing this:
PHP Code:

if (is_member_of($vbulletin->userinfo567))  
{
stuff only for members in groups 56, and 7
}
else
{
print_no_permission();



CEMarijn 03-13-2009 02:42 PM

Great, thanks for the quick reply, I'll get to it right away.

Dismounted 03-14-2009 04:10 AM

Or you could just use:
PHP Code:

if (!is_member_of($vbulletin->userinfo567))
{
    
print_no_permission();
}

// people that see this are authenticated 

print_no_permission() will end the execution of a script. :)


All times are GMT. The time now is 10:52 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01027 seconds
  • Memory Usage 1,718KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete