Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2015, 03:58 AM
MacroPhotoPro MacroPhotoPro is offline
 
Join Date: Feb 2012
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 04-10-2015, 08:55 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 04-10-2015, 01:13 PM
MacroPhotoPro MacroPhotoPro is offline
 
Join Date: Feb 2012
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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!
Reply With Quote
  #4  
Old 04-10-2015, 01:28 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The "do redirect" comment is meant to show where you'd put the code you posted at the end of post #1.
Reply With Quote
  #5  
Old 04-10-2015, 01:34 PM
MacroPhotoPro MacroPhotoPro is offline
 
Join Date: Feb 2012
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 04-10-2015, 02:10 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 04-10-2015, 02:25 PM
MacroPhotoPro MacroPhotoPro is offline
 
Join Date: Feb 2012
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #8  
Old 04-10-2015, 02:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 04-10-2015, 03:25 PM
MacroPhotoPro MacroPhotoPro is offline
 
Join Date: Feb 2012
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:17 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.06956 seconds
  • Memory Usage 2,251KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete