Current time: 05-24-2012, 11:58 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Restrict Access to Custom Pages
02-18-2009, 07:55 PM
Post: #1
How to Restrict Access to Custom Pages
Hi
I'm following THIS tutorial to make custom pages for my MyBB forum, and it works fine. What I'd like to know is how to restrict the pages so they are not accessible by:
a) certain usergroups
b) guests

Can anyone tell me the PHP needed to be added to my pages for this to happen?

Thank you.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-18-2009, 07:58 PM
Post: #2
RE: How to Restrict Access to Custom Pages
I'm not sure of the checks you'd have to do, but I know for the guest thing you can do:
PHP Code:
if($mybb->user['uid'] == 0)
 {
  
// It's a guest..
 
}
else
 {
  
// The person's a member.
 


Elite-Area / Last.FM Profile / PSN Name: XDaciD / Minecraft Map Progress: Coming Soon!

[Staff note - No referral links]
Visit this user's website Find all posts by this user
Quote this message in a reply
02-18-2009, 08:34 PM
Post: #3
RE: How to Restrict Access to Custom Pages
To allow Admin only...
PHP Code:
if($mybb->usergroup['cancp'])
{
     
// Code to execute for Admins only
}
else
{
     
error_no_permission(); // Display nice access error - Core MyBB function


Admins And Super-Moderators...
PHP Code:
if($mybb->usergroup['cancp'] || $mybb->usergroup['issupermod'])
{
     
// Code for Admins and Super Moderators
}
else
{
     
error_no_permission();


Usergroup specific...
PHP Code:
if($mybb->user['usergroup'] == || $mybb->user['usergroup'] == || $mybb->user['usergroup'] == 6)
{
     
// Code for those users in group 3, 5 and 6
}
else
{
     
error_no_permission();


Tom's example can be extended to:
PHP Code:
if(!$mybb->user['uid'] || $mybb->usergroup['isbannedgroup'])
{
     
error_no_permission(); // User is a guest or is in banned group, so no access
}
else
{
     
// Code for every member who is logged in

Find all posts by this user
Quote this message in a reply
02-19-2009, 12:02 PM
Post: #4
RE: How to Restrict Access to Custom Pages
These have been great replies, thank you.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-21-2009, 01:04 AM
Post: #5
RE: How to Restrict Access to Custom Pages
This user has been denied support. This user has been denied support.
It's shorter code to make the error_no_permissions function first and continue as this will not need the else statment....

Example...

Instead of this:
Code:
if($mybb->usergroup['cancp'] || $mybb->usergroup['issupermod'])
{
     // Code for Admins and Super Moderators
}
else
{
     error_no_permission();
}

You do this:
Code:
if(!$mybb->usergroup['cancp'] || !$mybb->usergroup['issupermod'])
{
     error_no_permission();
}

That's a cleaner method.

New MyBB plugin is "My Awards 2.0".
[Image: 468x60_SF.gif]
Visit this user's website Find all posts by this user
Quote this message in a reply
02-22-2009, 01:59 PM
Post: #6
RE: How to Restrict Access to Custom Pages
(02-21-2009 01:04 AM)labrocca Wrote:  
Code:
if(!$mybb->usergroup['cancp'] || !$mybb->usergroup['issupermod'])
{
     error_no_permission();
}

That's a cleaner method.

So I should just add the rest of my code underneath this?
Visit this user's website Find all posts by this user
Quote this message in a reply
07-04-2009, 12:39 AM
Post: #7
RE: How to Restrict Access to Custom Pages
It does not work for me.I am trying to prevent guests from seeing the Portal, not just not being able to link to it. I have tried all of the following...I've put it in the header, in the body...what could it be? I don't believe it makes any sense. By the way, very new to PHP, but very excited.

The only change I have made to Portal is stripping all of the content between the header and the footer, and replacing it with widgets and feeds.

First:
<?php if($mybb->user['uid'] == 0)
{
error_no_permission();
}
else
{
// Page Code
} ?>

Second:
<?php if(!$mybb->user['uid'] == 0)
{
error_no_permission();
}
else
{
// Page Code
} ?>

Third:
<?php if($mybb->user['uid'] == 0)
{
error_no_permission();
}
else
{ ?>
// Page Code
<?php } ?>

Fourth:
<?php if(!$mybb->user['uid'] == 0)
{
error_no_permission();
}
else
{ ?>
// Page Code
<?php } ?>

I've tried several variations of the above but to no avail. I would appreciate a nudge in the right direction.

Thank you!
Find all posts by this user
Quote this message in a reply
08-19-2009, 07:10 AM (This post was last modified: 08-19-2009 07:43 AM by sMoKiE.)
Post: #8
RE: How to Restrict Access to Custom Pages
Hi there!

I tried the same thing but if I add on top of portal.php this code:
Code:
<?php
if($mybb->user['uid'] == 0)
{
  echo "Sorry du hast keine Berechtigung fuer diese Seite..";
}
else
{
// Code of portal.php
}
?>
The script is unfortunately NOT going in ELSE even if I'm logged in. Does anybody can help me?


Alright, problem fixed! Had to add this code after loading global.php!
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication