1

Topic: Prevent guests from opening some pages

I have PunBB with Miniportal.
I have some php pages which I want users to login before they can see them.
When they click that page in the menu I need a message "You must login to see this page!"

My code is..

<?php

define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';

//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']) . ' / Page 6';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';

?>

<div> blah blah </div>

<?php

require PUN_ROOT.'footer.php';

What is the code that I should write in the page and where exactly should it go?

Many thanks in advance!

Re: Prevent guests from opening some pages

Try using

if($pun_user['g_id'] != PUN_GUEST)
{
//your code
}

3

Re: Prevent guests from opening some pages

What is ?

{
//your code
}

also where do I paste ?

if($pun_user['g_id'] != PUN_GUEST)
{
//your code
}

Re: Prevent guests from opening some pages

Sorry, I'll try to explain myself better.

<?php

define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';

//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']) . ' / Page 6';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';

if($pun_user['g_id'] == PUN_GUEST)
{
    echo 'You must login to see this page!';
}
else
{
?>

<div> blah blah </div>

<?php
}
require PUN_ROOT.'footer.php';

See if this works.

5

Re: Prevent guests from opening some pages

I have just tried that and I just get a white page whether logged in or not!

Re: Prevent guests from opening some pages

Are you sure? I just tested it locally and it works.

7

Re: Prevent guests from opening some pages

Yes, is it anything to do with Miniportal?

Re: Prevent guests from opening some pages

Not really, I copy pasted your code plus my modification, can I see a link please?

9

Re: Prevent guests from opening some pages

Sorry I had missed out the } in

<?php
}
require PUN_ROOT.'footer.php';

I was rushing it !

It seems to work ok, many thanks mate!

Re: Prevent guests from opening some pages

AlanB wrote:

Sorry I had missed out the } in

<?php
}
require PUN_ROOT.'footer.php';

I was rushing it !

It seems to work ok, many thanks mate!

Anytime wink

11 (edited by Tubby 2007-04-26 21:14)

Re: Prevent guests from opening some pages

rather than using the "echo" command punbb has a "message" command that is integrated. Try this out:

if ($pun_user['is_guest']) 
         message("You must be logged in to view this page!");

12

Re: Prevent guests from opening some pages

Thanks I will give it a go!

13

Re: Prevent guests from opening some pages

I'm having a trouble and wonder if anyone could help me?

I'm trying to include the following:

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

The troublem is that the php file i want to include it in is not i the same place as my forum.

The file where i want to include it in is on:
../chat

And the forum is on
../forum

How do I do this?

Thanks in advance big_smile

Re: Prevent guests from opening some pages

Well if you have chat/file.php and forum/include/common.php, you'd use ../forum/include/common.php.

Looking for a certain modification for your forum? Please take a look here before posting.

15

Re: Prevent guests from opening some pages

Thanks i got i working! big_smile

16

Re: Prevent guests from opening some pages

Hi, I'm currently trying to make my forum password protected and visible to members only. I was able to set up the index.php page successfully, but am running into trouble with the view_topic.php page (I tried using the code above). Does anyone have any experience with setting the topic pages to password protect or example they can point me to?