1

Topic: pun_status external use.

Hello,

I run a PunBB managed site. I wanted to know how to use pun_status, or a similar function on external pages of the /forums/ directory. Basically, I need to display something to the effect of "Welcome, Guest" or else "Welcome, User", on say website.com/index.php.

I tried looking for something small, though all I've found were large integration or conversion modifications.

Thanks

Re: pun_status external use.

I think  you would start by doing something in your website.com/index.php along the lines of:

<?php

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

- then the normal PunBB code that says welcome guest cut from punbb/s index.php

etc

Then you could call and use all the PunBB functions etc.

I am pretty sure this is the right approach.

3

Re: pun_status external use.

Hi,

Thanks, although that's actually what I tired first and it didn't quite work. I keep getting an access error probably due to my htaccess settings, though those can't be changed since it would have other negative effects on the site elsewhere.

Thanks anyway, I'll keep trying for a solution.

4

Re: pun_status external use.

Alright found a solution.

Although I'm still getting the error:

Warning: require() [function.require]: open_basedir restriction in effect.

PHP safe mode stuff? Any possible solution to this?

Re: pun_status external use.

Try require_once?

6

Re: pun_status external use.

No that didn't work either, though thanks. But I did find a final solution. All I needed to do was to use the full path to the forums instead of just '/forums'.

The code I'm using now is:

Included before Doctype:

<?php
define('PUN_ROOT', '/full/website/path/public/forums/');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'header.php';
?>

Included where needed:

<?php
        if ($pun_user['is_guest'])
        echo('Welcome, Guest!');
        
        else
        {
        echo('Welcome, '.$pun_user['username'].'!');
        }
?>

Basically a slimmed version of pun_status.

Thanks

Re: pun_status external use.

Cool that you solved it.

I feel stupid for just remembering that there is also this info right here on this site:

Website Integration

Integrating PunBB into your website code is easy if you know a little PHP. By including PunBB's script common.php, you gain access to all PunBB global variables such as $db and $pun_user. However, in order to include this file, you need to define a constant called PUN_ROOT. This constant should be set to the relative path to your PunBB forum directory. For example, if your website front page is located in /home/user/public_html/ and your forums are located in /home/user/public_html/forums/, your PUN_ROOT should be './forums/'. The PHP code to accomplish this could look something like this:

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

Once you've included common.php, you can access and utilize all of PunBB's global variables and functions. Typically, you will be most interested in the $pun_user array. This array holds information about the current user. Another interesting variable is the database object $db. How to use these variables in your own script is out of the scope of this document, but here's a small example showing you how to print a simple message greeting the current user on your website front page:

Hello <?php echo pun_htmlspecialchars($pun_user['username']); ?>!

In addition to defining PUN_ROOT, you can define a number of other constants to alter the behaviour of PunBB when including common.php. The two most interesting of these constants are PUN_TURN_OFF_MAINT and PUN_QUIET_VISIT. If PUN_TURN_OFF_MAINT is defined when including common.php, PunBB will not exit and display the maintenance message if the forums are placed into maintenance mode. You generally don't want this message to appear on your website front page, so defining that constant is a good idea. The other constant, PUN_QUIET_VISIT, prevents PunBB from updating the current user's last visit data in the database so that a visit to the front page doesn't count as a visit in the forums. This is also desirable behaviour in most cases. It doesn't matter what value you set these constants to, but setting them to a value of 1 is probably a good idea. Example:

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);

Please note that these constants must be defined before common.php is included.

from :
http://punbb.informer.com/docs/dev.html#integration

8

Re: pun_status external use.

Hey that info is great, thanks!