In: , , ,
On: 2004 / 08 / 14
Shorter URL for this post: http://ozh.in/1j

I run a community site that uses a phpBB2 forum, and I was wondering how to fetch informations from the forum into other pages (without messing with phpBB2 code, which is something I don't want to even hear about)
Here are some tips that may help you make your existing pages and phpBB2 communicate.

phpBB Fetch All

phpBB Fetch All : This project is a collection of functions you can easily use on any pages. Simple installation (5 or 6 pages in a forum sub-directory) and you have ready-to-use functions about posts (last posts, last topics, ongoing thread…), users (top posters, info about a random user…), polls and a lot of things. The doc pages are clear and list every function available.

This package contains almost everything I needed… Almost only, since there is no function to dectect informations from a login cookie, if any. It retrieves infos from the forum, but not from a user currently viewing a page.

Reading phpBB2's cookie

Hopefully, reading the login cookie is not difficult, I was real glad after a short googlage to realize how easy it was :) The following quick example just displays if the user has an ongoing session or cookie in your forums, you'll need to edit only line 5.

  1. <?php
  2. // phpBB includes
  3. define('IN_PHPBB', true);
  4. // next one is the physical path to your forums root : CUSTOMIZE
  5. $phpbb_root_path = '/home/user/you/forums/';
  6. include($phpbb_root_path . 'extension.inc');
  7. include($phpbb_root_path . 'common.'.$phpEx);
  8. // Start session
  9. $userdata = session_pagestart($user_ip, PAGE_INDEX);
  10. init_userprefs($userdata);
  11. // From now on, we have user infos
  12. if ($userdata&#91;'session_logged_in']) {
  13.        echo "You are : ".$userdata&#91;'username'] ." (".$userdata['user_email'].")<br>\n";
  14.        echo "Userid : ".$userdata['user_id']."<br>\n";
  15. } else {
  16.         echo "Not logged !";
  17. }
  18. ?>

The informations fetched can be any $userdata[thing] where thing is a field from phpbb2_users table : user_id, username, user_regdate, user_password, user_email, etc …

You can now use this informations into your existing site, for example auto-fill the comments form fields with username, user_url and user_email.

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/1j

Metastuff

This entry "Integration of phpBB2 into a site" was posted on 14/08/2004 at 11:38 pm and is tagged with , , ,

24 Blablas

  1. rail-flex says:

    Nice hints :)

    But let's recognize Invision is much better :)

  2. Integrating phpBB with WordPress
    My prayers have been answered!

    For quite a while now, I have been trying to figure out how to integrate phpBB with WordPress. I have known and used the phpbb_fetch_all mod for quite a while, but I had not figured out how to handle merging the two c…

  3. david clark says:

    How did you work around both applications having funcs named get_userdata()?

  4. Ozh says:

    The easiest way is to rename fetch_all's func to something else, like prefix them with "fa_" (this is quite quick as there arent so many functions)

  5. John says:

    Nice hints :)

    But let's recognize Invision is much better :)

    It has more features for sure, but it also costs a lot more. I don't think it's fair to look at these things from a simple this one is better than that one standpoint. The right tool for the job, in other words. It's also important to note that phpBB 3.0 is bringing many new features to the table.

  6. Sam says:

    >

    I'm trying to implement this as you say and have done so with all of my fetch_all functions. But it seems as if the same fix is required throughout all of phpbb (not just phpbb fetch all). Does that make sense? I'm a little nervous to make those changes, because I don't want to mess with my boards, but it would be great to integrate the boards with my WordPress.

    Thanks!

    Sam

  7. Ozh says:

    Why would you need to modify original phpBB functions ? fetch_all functions retrieve stuff from the phpbb tables, no matter their name is do_something or fa_do_something …

  8. Sam says:

    I'm getting this error

    Fatal error: Cannot redeclare get_userdata() (previously declared in /home/content/m/y/s/mysportsradio/html/wp-includes/functions.php:184) in /home/content/m/y/s/mysportsradio/html/boards/includes/functions.php on line 116

    I think may have something to do with common.php here:
    include_once ($phpbb_root_path . 'common.' . $phpEx);
    include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);

    I'm very novice at php so I'm pulling my hair out but want to get this solved. Thanks for your help!

  9. Ozh says:

    Yes, that's why you have to rename fetch_all's functions. But leave those in phpbb intact.

  10. Sam says:

    >

    This is what I have intended to do, yet I get this error. As mentioned, I'm a newb so I'm not at all clear what's going on with this.

  11. WDuluoz says:

    Ok, I have fooled with this again and again. The only place that get_userdata is being called is within wordpress and within phpbb. Fetch all does not have a get_userdata. The conflict is between wordpress and phpbb. The only way you could have managed to make this work is renaming the functions in wordpress. Is that the case?
    After changing the wordpress function names, I get this error when trying to call common.php
    Call to a member function on a non-object
    Any ideas?

  12. duncan says:

    If you're interested in logging in users to both your site and phpBB (if you have your own login code and want to have a single-sign-on), then look no further!

    I wrote a PHP class to take care of this:

    http://www.phpclasses.org/browse/package/1532.html

  13. Luke says:

    Like WDuluoz, I also cannot find any get_userdata vars to change in the phpBB Fetch All functions. The variable is within phpBB itself. How did you get around this?

  14. Jake says:

    I'm getting the following warning at the top of the page when I use this code. Any ideas on fixing it?

    Warning: Cannot modify header information – headers already sent by (output started at /home/path/roster.php:9) in /home/path/sessions.php on line 258

    Warning: Cannot modify header information – headers already sent by (output started at /home/path/roster.php:9) in /home/path/sessions.php on line 259

  15. Ozh says:

    you badly edited roster.php and it's outputting white spaces before sending the header. Probably blank spaces or lines before or after PHP tags.

  16. Jake says:

    Sorry, but I'm still not sure what I need to fix.

  17. Ozh says:

    One of your files is beginning or ending with spaces or new lines. Remove them.

  18. Jake says:

    I deleted " Title " and just started with "

  19. Jake says:

    That last comment didn't work. I deleted the HTML, HEAD, and TITLE opening and closing tags and just started with the php tag and it got rid of the error.

    Thanks.

  20. CoolGuy says:

    Hello,
    Greetings! I am trying to integrate PhpbBB script with a HTML page. How can i do it? I look forward to hear a earlier reply. Thank you very much for your time.
    Good regards.

  21. Ozh says:

    To the whole world » I loathe PHPBB2 and I ditched it months ago. Ask for support on phpbb2 sites, thanks :)

  22. Shawn says:

    Yeah, just thought I would leave a comment.
    I've used both IPB and phpBB, but the website I am updating is in a phpBB database…I'm finding myself pretty much re-writing the entire forums!

    Once I'm done it might be real nice to see since I'm implementing tons of ajax.

  23. XRumer255 says:

    Abnormal program termination.

  24. usedggues says:

    Good site :) Respect for admin…

Read more ?