Jump to content


This topic is now archived and is closed to further replies.


using phpbb sessions to gather other user-specific data

Recommended Posts

Ill start by saying I am fairly new to php, and I have learned most of what I know by "looking under the hood" and seeing how things work to get what I want. I realize this practice has put me at the mercy of others scripting habits, but I believe my needs are fairly simple.

I am currently working on a free project that involves a phpbb forum - yes, I know, they have their own forums for troubleshooting, but this isnt where my problem lies - and a set of tables used for a game, but the details are not entirely important.

Here is my problem. I can handle sessions just fine. Using various scripts and tutorials I have managed to create a 'index' login script for my  forums users. Like the Private message system, there is yet another system in place that ties accounts to aliases used for roleplaying and people can private message these aliases without knowing specific accounts, (i.e Account bob has aliases jim and john)

The desired effect is that when Account Bob logs in, he can access a page that shows private messages mailed to jim and john.

Ultimately, I would like a link on the front page thats like "bob has 3 new private messages" on the index, and then clicking that brings you to a page that allows you to see who they are from, view them, delete them, and write ones of your own.

So, Using the script I have in place, I figure I can query the database for messages linked to Bobs account in the 'if user is logged in' part, but really I am having trouble getting from the link to the page. I can provide more information if needed - my aim is teejaytank

Here's the script stuff I have for the login:

$phpbb_root_path = './forum/';

define ('IN_PHPBB', true);

if (!file_exists($phpbb_root_path . 'extension.inc'))
        die ('<tt><b>phpBB Front Page Login Error:</b>
                $phpbb_root_path is wrong and does not point to your forum.</tt>');

// phpBB related files

include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);

// Fetch All related files - we do need all these because the portal is a
// huge example

include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);

// start session management

$userdata = session_pagestart($user_ip, PAGE_INDEX);

$new_posts = phpbb_fetch_new_posts();

// disconnect from the database



And here is the part that handles logging in:
[code]<?php if ($userdata) { ?>
<p><?php if ($userdata['session_logged_in']) { ?>
<?php echo phpbb_avatar_image($userdata['user_avatar_type'], $userdata['user_avatar']); ?>
<?php echo ('Welcome to The Arena'); ?>,  [<?php echo $userdata['username']; ?>]</a>.<br />

<a href="<?php echo append_sid($phpbb_root_path . 'privmsg.php?folder=inbox');?>">
        if ($userdata['user_new_privmsg'] == 0) {
                echo ('0 new messages'); }
        elseif ($userdata['user_new_privmsg'] == 1) {
                printf($lang['New_pm'], $userdata['user_new_privmsg']); }
        else {
                printf($lang['New_pms'], $userdata['user_new_privmsg']); }

<br />
                <a href="<?php echo append_sid($phpbb_root_path . 'search.php?search_id=newposts'); ?>">
                <?php echo ('new posts'); ?> [<?php echo $new_posts['total']; ?>]</a><br />
<form action="<? echo append_sid($phpbb_root_path . 'login.php?logout=true'); ?>" method="post" target="_top">
<input type="hidden" name="username" value="logout" />
        <input type="hidden" name="password" value="logout" />
        <input type="hidden" name="redirect" value="../index.php" />
        <input type="submit" name="logout" value="Log Out" />
<input type="hidden" name="sid" value="<?php echo $userdata['session_id']; ?>" />
<?php } else { ?>
                <?php echo('Welcome to The Arena,'); ?> <?php echo $lang['Guest']; ?>.
<?php } ?>
<?php } ?>
<!-- USER -->

<!-- LOGIN -->
<?php if (!$userdata or !$userdata['session_logged_in']) { ?>
<form action="<? echo $phpbb_root_path; ?>login.php" method="post" target="_top">
<?php echo $lang['Username']; ?>:<br />
<input type="text" name="username" size="20" maxlength="40" value="" /><br />
<?php echo $lang['Password']; ?>:<br />
<input type="password" name="password" size="20" maxlength="25" /><br />
<input type="checkbox" name="autologin" /> <?php echo('Remember Me'); ?><br />
<input type="hidden" name="redirect" value="/devel/index.php" />
<input type="hidden" name="sid" value="<?php echo $userdata['session_id']; ?>" />
<input type="hidden" name="outside" value="1" /><br />
<input type="submit" class="mainoption" name="login" value="Login" />
<!-- <a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=sendpassword'); ?>"><?php echo $lang['Forgotten_password']; ?></a> -->

<br />
<?php } ?>


Now like I said, the link shouldnt be very hard. I could probably use the $userdata stuff to do a quick query to see if there are any unread posts. I simply tried making a link and echo the username on a new page, but it doesnt seem that the information is being held.. Is there anything else I can provide for info?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.