vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Controlling access to external pages via vB credentials (https://vborg.vbsupport.ru/showthread.php?t=61740)

dontpanic 02-19-2004 06:13 PM

Controlling access to external pages via vB credentials
 
In vB 2.x I was able to use this code to control access to a page based on member group.
PHP Code:

<?php
error_reporting
(7);

require(
'./global.php');

if (
$bbuserinfo[usergroupid]=="1" or $bbuserinfo[usergroupid]=="3" or $bbuserinfo[usergroupid]=="0") {
      eval(
"dooutput(\"".gettemplate('newsletter_subscribe_error')."\");");
      }else{        
eval(
"dooutput(\"".gettemplate('newsletter_subscribe')."\");");
}
exit;

?>

I'm missing something when I try to convert it over....can someone please show me what this should look like to accomplish the same basic goal in vB 3.x?

Thanks!

assassingod 02-19-2004 06:19 PM

Most of the variables and functions have changed in vB3 now, you should use something like
PHP Code:

 <?php
     error_reporting
(E_ALL & ~E_NOTICE);
      require(
"./global.php");
      
      
$globaltemplates = array(
          
'newsletter_subscribe_error',
          
'newsletter_subscribe'
      
);
      
      if(
in_array($bbuserinfo['usergroupid'], array(0,1,3)))
      {
          eval(
'print_output("' fetch_template('newsletter_subscribe_error') . '");');
      }
      else
      {
          eval(
'print_output("' fetch_template('newsletter_subscribe') . '");');
      }
  
?>


dontpanic 02-19-2004 06:25 PM

OK, lemme try it out and I'll let you know how it went.

Thanks! :)

Zachery 02-19-2004 06:25 PM

Should that be require_once ? :P

assassingod 02-19-2004 06:27 PM

It doesn't have to but yes it can be.

dontpanic 02-19-2004 06:44 PM

OK, works like a charm. I just dropped the correct code into a pre-existing page as you can see:
PHP Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''index');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// pre-cache templates used by all actions
$globaltemplates = array(
    
'navbar',
    
'flash1',
    
'STANDARD_ERROR'
);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/functions_bigthree.php');
require_once(
'./includes/functions_forumlist.php');

// ### ALL DONE! SPIT OUT THE HTML AND LET'S GET OUTA HERE... ###

      
if(in_array($bbuserinfo['usergroupid'], array(6,11)))
      {
          eval(
'$navbar = "' fetch_template('navbar') . '";');
          eval(
'print_output("' fetch_template('flash1') . '");');
      }
      else
      {
          eval(
'print_output("' fetch_template('STANDARD_ERROR') . '");');
      }
?>

If we are evaluating members who's primary user group is 6 or 11, it works great. That's administrators and a subscription group. However, if you are a member of the subscription group (11) and its a secondary group, it does not work correctly, you fall into the else statement. Thoughts?

assassingod 02-19-2004 06:54 PM

Can't think why that's happening. Also, theres unnessacary code in that script
(Unless you need to require bigthree.php and forumlist.php)

dontpanic 02-19-2004 06:59 PM

Yeah, I got rid of those two requires...I didn't notice them at first. The only solution I see is to have the subscription event change the primary user group from 1 to 11 instead of configuring it as a secondary user group....I can't see that this would be a problem, but I'm not sure.

assassingod 02-19-2004 07:00 PM

What I would do is use 1 print_output and use the fetch_templates in each if section.

E.g;
PHP Code:

 <?php
 
 
// ####################### SET PHP ENVIRONMENT ###########################
 
error_reporting(E_ALL & ~E_NOTICE);
 
 
// #################### DEFINE IMPORTANT CONSTANTS #######################
 
define('NO_REGISTER_GLOBALS'1);
 
define('THIS_SCRIPT''pagename');
 
 
// ################### PRE-CACHE TEMPLATES AND DATA ######################
 // pre-cache templates used by all actions
 
$globaltemplates = array(
     
'navbar',
     
'flash1',
     
'STANDARD_ERROR'
 
);
 
 
// ######################### REQUIRE BACK-END ############################
 
require_once('./global.php');
 
 
 
// ### ALL DONE! SPIT OUT THE HTML AND LET'S GET OUTA HERE... ###
 
       
if(in_array($bbuserinfo['usergroupid'], array(6,11)))
       {
       eval(
'$var1 = "' fetch_template('template-for-usergroupids-specified') . '";');
       }
       else
       {
       eval(
'$var1 = "' fetch_template('template-for-everyone-else') . '";');
       }
       
       eval(
'$navbar = "' fetch_template('navbar') . '";');
       eval(
'print_output("' fetch_template('main-template-here') . '");');
 
?>

Then use $var1 in the main-template-here template.

dontpanic 02-19-2004 07:04 PM

OK, so what would that look like? I'm not quite seeing it...been a long day. :ermm:


All times are GMT. The time now is 07:04 AM.

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.01129 seconds
  • Memory Usage 1,762KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete