Trying to restrict access to webpaged based on forum login? (MyBB)

Fearghal

Member
Messages
286
Reaction score
0
Points
16
Hi, I wonder if someone could help me out here...

I have a standard website with no forums, just pages. I then have a forums subdomain where I run a MyBB board. Can anyone advise me on how I would go about restricting a page on the standard site, based on whether or not the user is logged into the forums?

Example, restrict access to www.example.com/vip.php to only allow access to users who are logged in to www.forums.example.com.

Any suggestions?
Thanks
 
Last edited:

Fearghal

Member
Messages
286
Reaction score
0
Points
16
Thanks for the reply, sadly that won't work for me as it would affect the layout of my site.
 
Last edited:

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
I think you can include forum's authorization script to normal pages for example /home/you/forums/authorize.php can be included in /home/you/public_html/hidden_treasure.php to check if user is logged in or not if not show the login form or redirect to forum.
 

techairlines

x10 Flyer
Community Support
Messages
2,867
Reaction score
165
Points
63
I get - Parse error: syntax error, unexpected '{' in /home/standard/public_html/test.php on line 57...

Hmm sounds like you have an unncessary { tag somewhere. If all the PHP code isn't large, could you possibly post it here so we can examine the code you used?
 

Fearghal

Member
Messages
286
Reaction score
0
Points
16
I only put in the code I got from here to test it...

Code:
<p><?php
$allowedgroups = array ( '4', '8' );
if ( in_array ( $mybb->user['usergroup'], $allowedgroups )
{
    // code here
}
else
{
    die ( 'Uh oh, accessing stuff you\'re not supposed too. ;)' );
}
?></p>
 
Last edited:

techairlines

x10 Flyer
Community Support
Messages
2,867
Reaction score
165
Points
63
You need to include the code snippets mentioned in this thread: http://community.mybb.com/thread-6615.html then wrap that in the code in the link I mentioned above.

Also, the error message mentions Line 57 and there doesn't appear to be a line 57 there.

Try this slightly modified version instead:

PHP:
$allowedgroups = array ( '4', '8' );
if ( in_array ( $mybb->user['usergroup'], $allowedgroups ) )
{
    // code here
}
else
{
    die ( 'You can\'t access this page!' );
}

Put the custom page code (http://community.mybb.com/thread-6615.html) into the // code here section.
 
Last edited:

gomarc

Member
Messages
516
Reaction score
18
Points
18
Hi Fearghal,

Based on techairlines instructions, I’m providing you with a working example.

For this test, create a new directory in the root of your forums and call it whatever you want (I called mine “mytest”). You forums root directory is the one that has these directories: admin, archive, cache, images and others.

Place a copy of your standard web page in this new directory.

Add the following php code to the beginning of your page:

PHP:
<?php

define('IN_MYBB', 1);
require_once "../global.php";

$allowedgroups = array ( '4', '8' );
if (!in_array ( $mybb->user['usergroup'], $allowedgroups ))
{
    die ( 'You can\'t access this page!' );
}

?>
Rename the page so that the extension is ".php" (not html)

This is the full example of what I tested and it works fine.

PHP:
<?php

define('IN_MYBB', 1);
require_once "../global.php";

$allowedgroups = array ( '4', '8' );
if (!in_array ( $mybb->user['usergroup'], $allowedgroups ))
{
    die ( 'You can\'t access this page!' );
}

?>

<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <title></title>
  </head>
  <body>
    <h1>
          My site has a really nice layout
          and design and I want to keep it like that
    </h1>
  </body>
</html>
Finally, just let me add that this method is not very secure and quite vulnerable, so please be careful what you post.
 
Top