Topic: Using the login system of PunBB.

Hello,

Sorry for my English, at first. I know that it's not very good, but I'll try my best. :-)

I'm very happy testing (and using soon hopefully) PunBB - it's quiet an easy and very functional board system. Till now I only tested the functions - now I want start integration the system into my page.

My situation: I want to set other pages of the site with a password - like the user groups in the forum. So, if you login to the forum, it should be possible to surf on the page - being logged in all the time. And if you enter a page, I want to set the following oppotunitys: a) Not logged in (Error & Login-Field), b) Logged in, but the wrong rights = in the wrong user group (Error) and c) Loggin in successfully -> see the content of this site.

Is this possible with the system of PunBB?

I hope you unterstood what I want to say.

Thx,
d.

2

Re: Using the login system of PunBB.

http://punbb.org/docs/dev.html#integration

Re: Using the login system of PunBB.

Hi!

Thanks for your help. I included the common.php now.
But how can I use a variable to check if the user is logged in / if the logged in user is member of a special user group?

And:
If you login at the board and than check the website (other pages with the common.php included) - do you stay at the status "logged in"?

Thanks!
D.

Re: Using the login system of PunBB.

Check if a user is logged in: $pun_user['is_guest']
Member of a user group: $pun_user['g_id'] == SOME_NUMBER

And yes, if common.php is included then you're properly authenticated, just like on a PunBB page.

Re: Using the login system of PunBB.

Ok, thanks for your help so far.

At the moment I have a problem including the board into my normal website design.

I have got an index.php for my design, and at the content part I have a switch where I include content parts of my page. For example, the script checks index.php?section=contact and includes at that position the content of a file with a contact form.

Now I included the common.php in the file index.php and want to include the board at the content area if the variable is called "board". But when I want to include the board/index.php, this error appears:

Fatal error: Cannot redeclare check_cookie() (previously declared in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/include/functions.php:28) in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/include/functions.php on line 112

What is wrong?
I only found an explaination to include in the PuBB template, but I want to do it the other way around.

Thanks a lot!

6

Re: Using the login system of PunBB.

Only include/require common.php once. Require it in the parent script alone, and not in the required/included script.

Re: Using the login system of PunBB.

MattF wrote:

Only include/require common.php once. Require it in the parent script alone, and not in the required/included script.

I only included the common.php once in the index.php. The define/require is only once at the top of index.php.

How do I include generell content (not the board)?

At the place, where the content should be displayed is this code:

<?
switch($_GET['section']){
case "news": include("news.php"); break;
case "links": include("includes/links.php"); break;
default: include("news.php"); break;
}
?>

So, if you type in index.php?section=links you see the page with the links. Now, based on that, I want to include the board:

case "board": include("board/index.php"); break;

PunBB is in the dictionary /board/. But if I run the index.php with index.php?section=board the error in my last post appears.

common.php is included only once - at the top of index.php.

Thanks!

8

Re: Using the login system of PunBB.

that is not the correct method to use, when you do

case "board": include("board/index.php"); break;

you include a complete page with its own structure and dependencies. Common.php is included in the forum pages but you already included it in you index.php

9 (edited by Klappspaten 2008-04-27 12:51)

Re: Using the login system of PunBB.

Okay, i see. I've corrected the code:

<?
if($_GET['section'] != board) {
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', './board/');
require PUN_ROOT.'include/common.php';
}
?>

But now, when I try to open index.php?section=board, the following error appears:

Warning: require() [function.require]: Unable to access ./include/common.php in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/index.php on line 27

Warning: require(./include/common.php) [function.require]: failed to open stream: No such file or directory in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/index.php on line 27

Fatal error: require() [function.require]: Failed opening required './include/common.php' (include_path='.:/srv/www/httpd/phost/d/de/pytalhost/dav/web/') in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/index.php on line 27

I don't exactly know what it means, but I think the script is missing the common.php.
What is wrong?

Thanks a lot!

Re: Using the login system of PunBB.

Smartys wrote:

Check if a user is logged in: $pun_user['is_guest']
Member of a user group: $pun_user['g_id'] == SOME_NUMBER

A wrote a piece of code to check, if the user has logged in. The group with the number 5 is the standart-group where all users, who get registrated, have to wait for their (manuell) activation. For registered and activated users, I want to use this piece of code:

if ($pun_user['is_guest'==false] && $pun_user['g_id']!=5)
{ ...
}

But if I check the page, I get the message of the else tag. But im registrated and in der group Administrators - which hasn't got the ID 5.

Thanks!

Re: Using the login system of PunBB.

That code is incorrect

if (!$pun_user['is_guest'] && $pun_user['g_id'] != 5)
{
}

or

if ($pun_user['is_guest'] == false && $pun_user['g_id'] != 5)
{
}

You put the == false within the ], which is wrong.

Re: Using the login system of PunBB.

OK, that was stupid. smile
Thanks for your support.

13

Re: Using the login system of PunBB.

Klappspaten wrote:

Okay, i see. I've corrected the code:

<?
if($_GET['section'] != board) {
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', './board/');
require PUN_ROOT.'include/common.php';
}
?>

But now, when I try to open index.php?section=board, the following error appears:

Warning: require() [function.require]: Unable to access ./include/common.php in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/index.php on line 27

Warning: require(./include/common.php) [function.require]: failed to open stream: No such file or directory in /srv/www/httpd/phost/d/de/pytalhost/dav/web/ema09/board/index.php on line 27

That error message and the defined path in that code above would appear to be contradictory.

Re: Using the login system of PunBB.

No, they're not: it's just the wrong code. That's the code used when section is NOT board, which it is here.

Re: Using the login system of PunBB.

Thanks - I solved all problems with your help. smile