vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   RE-DIRECTING TO REGISTER Based on Permissions (https://vborg.vbsupport.ru/showthread.php?t=318190)

MacroPhotoPro 04-10-2015 03:58 AM

RE-DIRECTING TO REGISTER Based on Permissions
 
Hi;

I have created custom pages that I only want subscribed (paying) members to be able to view.

If an unregistered/registered member (who has not paid) tries to view, I have created a re-direct with the following code:

Code:

// Permissions Redirect
        if ($usergroupid==8) {
                header("Location: $url_register");
        } else if ($usergroupid <= 1) {
                header("Location: $url_register");
        } else if ($usergroupid <= 2) {
                header("Location: $url_payments");
        } else if ($usergroupid <= 3) {
                header("Location: $url_payments");
        } else if ($usergroupid <= 4) {
                header("Location: $url_payments");
        }

User Group 1 = Unregistered;
User Group 2 = Registered;
User Group 3 = Awaiting Email;
User Group 4 = In Moderation;

However, the page is not redirecting properly.

What am I doing wrong in my coding?

Any help would be very much appreciated,

Jack

--------------- Added [DATE]1428650994[/DATE] at [TIME]1428650994[/TIME] ---------------

Someone PM'd me this coding, and it works, but unfortunately it directs every user group to register:

Code:

if (!$vbulletin->userinfo['userid'] AND THIS_SCRIPT != 'register')
{
        header("Location: " . $vbulletin->options['bburl'] . "/register.php");
}

How do I code it to be specific, to one (or more) select user groups?

Would appreciate some help :)

kh99 04-10-2015 08:55 AM

If you have a usergroupid and you want to check it, you could do this:
Code:

if (in_array($usergroupid, array(1, 2, 3, 4)))
{
 // do redirect
}


Or to check the current user you could do this:
Code:

if (is_member_of($vbulletin->userinfo, 1, 2, 3, 4))
{
 // do redirect
}


Of course you could also use !is_member_of and only list the usergorups that should have access, if that's easier.

MacroPhotoPro 04-10-2015 01:13 PM

Thank you very much.

How does it know to redirect the user to register.php?

--------------- Added [DATE]1428679328[/DATE] at [TIME]1428679328[/TIME] ---------------

Could you elaborate on do redirect?

--------------- Added [DATE]1428679709[/DATE] at [TIME]1428679709[/TIME] ---------------

Quote:

Originally Posted by kh99 (Post 2542754)
Of course you could also use !is_member_of and only list the usergorups that should have access, if that's easier.

I think this would be easier, would you mind showing me how to do this? This will be for a specific, customized .php page.

Thank you!

kh99 04-10-2015 01:28 PM

The "do redirect" comment is meant to show where you'd put the code you posted at the end of post #1.

MacroPhotoPro 04-10-2015 01:34 PM

You mean this?

Code:

if (is_member_of($vbulletin->userinfo, 1, 2, 3, 4))
{
 header("Location: " . $vbulletin->options['bburl'] . "/register.php");
}

It doesn't seem to be working.

kh99 04-10-2015 02:10 PM

Where are you putting that code exactly? It would only work if your custom pages include vbulletin's global.php, and that redirect code would have to be after global.php was included.

MacroPhotoPro 04-10-2015 02:25 PM

I have a custom vBB page, and here is where I am trying to insert the code:

Code:

<?php

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

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'srcImages');
define('CSRF_PROTECTION', true); 
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('IMAGE_HOSTING',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
$navbits = construct_navbits(array('' => 'Image Hosting'));
$navbar = render_navbar_template($navbits);

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


if (is_member_of($vbulletin->userinfo, 1, 2, 3, 4))
{
 header("Location: " . $vbulletin->options['bburl'] . "/register.php");
}

--------------- Added [DATE]1428683561[/DATE] at [TIME]1428683561[/TIME] ---------------

I think it might be easier to just list the user groups that can access the page.

What would the code be for that?

kh99 04-10-2015 02:59 PM

Well, first we need to figure out why it's not working right. You said before that this code did the redirect but for everyone?
Code:

if (!$vbulletin->userinfo['userid'] AND THIS_SCRIPT != 'register')
{
        header("Location: " . $vbulletin->options['bburl'] . "/register.php");
}


And what I suggested didn't redirect anyone?

MacroPhotoPro 04-10-2015 03:25 PM

I think I have it figured out. The following seems to work:

Code:

        // Permissions Redirect
        if ($usergroupid==8) {
                header("Location: $url_/register.php");
        } else if ($usergroupid <= 1) {
                header("Location: $url_/register.php");
        } else if ($usergroupid <= 2) {
                header("Location: $url_/payments.php");
        } else if ($usergroupid <= 3) {
                header("Location: $url_/payments.php");
        } else if ($usergroupid <= 4) {
                header("Location: $url_/payments.php");
        }

So far, so good. If I run into trouble again, I will re-post here, but I think I got it licked :)

Thank you for your time!

Jack

--------------- Added [DATE]1428686841[/DATE] at [TIME]1428686841[/TIME] ---------------

PS: I would be interested to see your code where only members X, Y could have access ... with all others getting a No Permissions message.


All times are GMT. The time now is 07:02 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.01075 seconds
  • Memory Usage 1,742KB
  • 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
  • (8)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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