Wednesday, April 30th, 2008...7:28 pm

Using Phpbb3 Avatars In Custom Pages

Jump to Comments

Recently I’ve been working on a custom web app that integrates with phpbb3. In this app, I’d like to have a custom user profile page. I have my own ‘users’ table and the link between the two is the “user_id” field which I set when the user first enters the app. Throughout, however, there are “Submitted By:” sections with links to the user’s profile page.

On said profile page, I’d like to show the user’s avatar straight from phpbb. This took some hackery, but I finally got it working. Behold.

First off, if you’re not already doing phpbb session management, here’s that code. This requires your phpbb user to be logged in:

define(’IN_PHPBB’, true);

//replace $phpbb_root_path with path to your forum<
$phpbb_root_path = ‘../forum/’;
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
include($phpbb_root_path . ‘common.’ . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

Next, we need to include the phpbb functions file so we can run the function “get_user_avatar”:

include($phpbb_root_path . ‘includes/functions_display.’ . $phpEx);

Now, for the business:

//close the current DB connection, where $OPEN_CONNECTION is your MySQL connection
//mysql_close($OPEN_CONNECTION);
//then go to the forum DB and get this user’s avatar info
//include your forum’s ‘config.php’ file — this is custom
//to wherever that file is!!

include (’../forum/config.php’);

//connect to the forum’s database
$db2 = mysql_connect($dbhost, $dbuser, $dbpasswd)
or die(”Unable to connect to MySQL”);
$selected = mysql_select_db($dbname,$db2)
or die(”Could not select the database”);

//here’s the SQL query. REPLACE “$USER_ID”
//with the user id you’d like to query.
$sql = ‘SELECT `user_avatar`, `user_avatar_type`, `user_avatar_width`,
`user_avatar_height` FROM `phpbb_users`
WHERE `user_id` = ‘ . $USER_ID . ”;
$result2 = mysql_query($sql); $row = mysql_fetch_array($result2);

//finally, this will return the avatar
echo get_user_avatar($row['user_avatar'],
$row['user_avatar_type'], $row['user_avatar_width'],
$row['user_avatar_height']);

That’s it! Enjoy.

Tags: > > > >

3 Comments

  • Hey that sounds like a good idea, I’ve been looking around for an extra feature to add to PHPBB3 to allow users to have there own Profile page..

    Let me know where and how your getting along with that.

    Goodluck & cheers

  • Hi Garret. I used this script to create a profile page outside of phpbb. I added another table (which linked using the phpbb user id) and stored misc information there. Creating an “add/edit details” page was simple. Post up if you have any specific questions.

    cheers.

  • Hello. It is test.

Leave a Reply