Topic: Website/PunBB Integration

I want my website to be able to read and utilize my punBB's cookie so that I can have them logged into my website and punBB simultaneously.

This is the code in 'include/functions.php' of my punBB 1.2.11 that successfully reads my punBB's coookie. I have only added a notice message within.

if (isset($_COOKIE[$cookie_name]))
    list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]);

// Code I've added to inform members of a dilema.
echo '<strong>Website login is offline.</strong><br>Mboard login is working.<br><small>['.$cookie['user_id'].'] '.$cookie_name.'</small><p>';

if ($cookie['user_id'] > 1)
{

This is the code on the page of my website that fails to read my punBB's cookie (so that a user may be logged in to my website and the message board simultaneously).

    if (isset($_COOKIE[$cookie_name]))
        list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]);

// Code I've added to inform members of a dilema.
echo '<strong>Website login is offline.</strong><br>Mboard login is working.<br><small>['.$cookie['user_id'].'] '.$cookie_name.'</small><p>';

    if ($cookie['user_id'] > 1)
    {

The variable $cookie['user_id'] never returns any data when called by my website (as in the code above). Besides four extra tabs, the code is identical. Why does this code not work when used on the website? (that the punBB is part of)

Website is located at the main directory. The punBB is within a folder called 'mboard2'.
The cookie is valid, as I can run around logged in to the punBB with no trouble at all.
The value of $cookie_name in both codes is identical.
And aren't isset, list, unserialize all native PHP functions?

Back when I had punBB 1.5.1 (I just recently upgraded to 1.2.11 which is a vast improvement) I was able to do the following:
? Users could login to my website -> this would also simultaneously log them into the message board.
? Users could login to the messageboard -> this would also simultaneously log them into the website.
? ( Logging out worked exactly the same. I even managed to get stylesheet changes on either to update on the other. )
But with punBB 1.2.11, I am having trouble restoring this much-needed ability because of the code mentioned above.

Re: Website/PunBB Integration

Just use this code to include PunBBs cookie data and allow access to punbb's functions

//Path from current location to forum folder
define('PUN_ROOT', './path/to/forum');
//This stops posts getting marked as read when people only view this page
define('PUN_QUIET_VISIT', 1);
//Load PunBBs functions and variables
require PUN_ROOT.'include/common.php';

you can then use $pun_user['is_guest'] to find out if i user is a guest or not

Re: Website/PunBB Integration

That's much more effecient and actually may open up possibilities I hadn't previously thought of!

I have put this code on my 'create_data.php' that every page includes. And everything works for any page in my root directory that calls 'data.php'. But that's only two pages... Most of my pages (that call 'data.php') are not located in the root directory, so I get the error:

Warning: main(./mboard2/include/common.php): failed to open stream: No such file or directory in /home/twallnet/public_html/login/create_data.php on line 10

Also my server has 'open_basedir' protection enabled, which is screwing up every alternative code I've come up with. I am very sad sad

Re: Website/PunBB Integration

well you'll need to put define('PUN_ROOT', './path/to/forum'); in each individual file rather than in your main include

alternatively you could change the current directory before and after including punbb, but i'm not sure what the excat code is for that / if it would work at all.

Re: Website/PunBB Integration

connorhd,
so i can design any type of layout and have them connected to the forum for membership and i can set it where member only page by adding

<?php

define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
if ($pun_user['g_read_board'] == '0')
    message($lang_common['No view']);

//Hide contest from Guest
if ($pun_user['is_guest'])
   message($lang_common['No permission']);


at the top of the page.
so i can leave out the.

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

and it doesnt pull the header or anyother thing from the site?

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: Website/PunBB Integration

yes

7 (edited by yi3artist 2006-04-02 06:44)

Re: Website/PunBB Integration

Tried a change directory function I found on PHP's site, chdir(), but couldn't get it to be useful. Time to add that punBB access code to every file! Thank you for the help.

Re: Website/PunBB Integration

What i was thinking of was

//Path from current location to forum folder
define('PUN_ROOT', './path/to/forum');
//This stops posts getting marked as read when people only view this page
define('PUN_QUIET_VISIT', 1);
//Save the directory we are currently in
$currentdir = getcwd();
//Change directory to the one the main file is in
chdir('/path/to/included/file/');
//Load PunBBs functions and variables
require PUN_ROOT.'include/common.php';
//Change directory back
chdir($currentdir);

9 (edited by yi3artist 2006-04-02 12:31)

Re: Website/PunBB Integration

Might work, but I already changed all my files. And I have a new problem, whee! (I still would have this same new problem, I believe, even if a chdir() action had been used instead.)

PunBB seems to be preventing my webpages from using the php variables I pass at the end of URLs. I can see that the URL includes the php variable I pass, but when the page parses, the variable is empty.

I have this code on every page that need have it. (And /path/to/forum has been replaced with the appropiate path on each page.)

//Path from current location to forum folder
define('PUN_ROOT', './path/to/forum');
//This stops posts getting marked as read when people only view this page
define('PUN_QUIET_VISIT', 1);
//Load PunBBs functions and variables
require PUN_ROOT.'include/common.php';

My URLs passed php variables fine before giving my site constant access to punBB like so. What's up? sad

Edit: Also all pages that once succesfully recieved data from forms are no longer recieving that data. Only the code to access punBB has been added to any page.

Re: Website/PunBB Integration

use $_GET['varname'] it is a better way to do it anyway.

Re: Website/PunBB Integration

I love you,

Thanks.

12

Re: Website/PunBB Integration

ConnerHD
so i can make a whole site and include membership and forum from the page that i created?
example beginning works
http://nalan.org/test

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: Website/PunBB Integration

Hello ;

I have done this one my website

<?php define('PUN_ROOT', 'forum/'); ?>
<?php include_once PUN_ROOT.'include/common.php'; ?>

and this

<?

          
            if($pun_user['is_guest']){ // If the user is guest
            ?>
            
            <li><a id="r" href="http://www.jdskins.com/forum/register.php">S'inscrire</a></li>
            <li><a id="fp" href="http://www.jdskins.com/forum/login.php?action=forget">Mot de passe perdu</a></li>
            
            <form id="login" method="post" action="http://www.jdskins.com/forum/login.php?action=in" onsubmit="return process_form(this)">
            <p><input type="hidden" name="form_sent" value="1" />
            <input type="hidden" name="redirect_url" value="/index.php" /></p>            
            <p class="upinputspace"><input class="upinput" type="text" value="<?php echo $lang_common['Username'] ?>" name="req_username" tabindex="1"/></p>
            <p class="upinputspace"><input class="upinput" type="password" value="<?php echo $lang_common['Password'] ?>" name="req_password" tabindex="2"/></p>
            <p class="upsubmitspace"><input class="upsubmit" type="submit" name="login" value="OK" tabindex="3" /></p>
            </form>
            
            <?
            }else{ // The user is registered
    
             echo "<ul id='userlinks'>";
         echo "<li><a href='/forum/profile.php?id=".$pun_user['id']."'>Profile</a></li>";
             echo "<li><a href='/forum/search.php?action=show_new'>Nouveau(x) Post(s) sur le Forum</a></li>";
         echo "<li><a href='/forum/message_list.php'>Message(s) Privé(s)</a></li>";
             echo "<li><a href='/forum/login.php?action=out&id=".$pun_user['id']."'>Deconnexion</a></li>";
             echo "</ul>";
            
            }
            ?>

and no way it's say to me when i'm being log on but when i go back to the site i'm not loged

any idéa ?