Wednesday, April 30th, 2008...7:28 pm
Using Phpbb3 Avatars In Custom Pages
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.
6 Comments
September 21st, 2008 at 10:14 am
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
September 21st, 2008 at 10:35 am
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.
November 18th, 2008 at 5:11 pm
Hello. It is test.
April 9th, 2009 at 10:35 am
jon, how did you get it to pull the info outside off phpbb?
April 9th, 2009 at 11:02 am
@Steve — the first part of code in this article sets you up to access all the phpBB user controls outside of phpBB. Place that piece in a PHP file outside of phpBB and dump $user object and you should see all the necessary info. From there, use the other bits of code to grab the avatars.
June 14th, 2009 at 9:48 pm
I’m new here on the forum, found it by searching google. I look forward to chatting about various topics with all of you.
Leave a Reply