MyBB Community Forums

Full Version: Require login to view custom .php page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
To solve the problem found yesterday ( http://community.mybb.com/thread-165135.html ) i've moved the content of that directory in "/" but i still find that everybody can access those pages, knowing the exact url.

So, how can i force users to login in order to view those pages or block guests and banned users from viewing?
In a php file you can put this:
<?php
define("IN_MYBB", 1);
require_once "global.php";
if(!$mybb->user['uid'])
{
error_no_permission();
}
// Rest of code
?>
Edit: delayed response

see replies here
if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission();
(01-05-2015, 03:11 PM)dragonexpert Wrote: [ -> ]In a php file you can put this:

<?php
define("IN_MYBB", 1);
require_once "global.php";
if(!$mybb->user['uid'])
{
error_no_permission();
}
// Rest of code
?>

It looks right but i get an error on line 7

[Image: 0cbc88e51743dc6d2a411624ea9282df.png]

[Image: 02d46a811cc4ace06ece95588ac64fbc.png]
See my edit. It placed an extra quotation mark.
(01-05-2015, 03:17 PM).m. Wrote: [ -> ]Edit: delayed response

see replies here

if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission();

doesn't work, no errors but i can see the page when logged out

(01-05-2015, 03:19 PM)dragonexpert Wrote: [ -> ]See my edit.  It placed an extra quotation mark.

it worked this time, thanks a lot! Big Grin
^ as you want to block php pages for both guests & banned users, the other code should also work
if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission(); 
(01-05-2015, 03:32 PM).m. Wrote: [ -> ]^ as you want to block php pages for both guests & banned users, the other code should also work

if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission(); 

I've attempted with that too but i can access the page as guest...
since guests group id is 1 i cannot understand this :/

edit: btw issue has been solved forcing user to login with the other code so i have nothing to complain Smile
^ fine. I don't want to argue. BUT tested it once again on MyBB 1.8.3
<?php
define("IN_MYBB", 1);
require_once "global.php";

if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission(); 

// Rest of code
echo 'MyBB';
?>
(01-05-2015, 03:44 PM).m. Wrote: [ -> ]^ fine. I don't want to argue. BUT tested it once again on MyBB 1.8.3

<?php
define("IN_MYBB", 1);
require_once "global.php";

if (in_array($mybb->user['usergroup'] , array(1,7))) error_no_permission(); 

// Rest of code
echo 'MyBB';
?>

this time it worked Smile
Pages: 1 2