This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

phpBB3 Sessions Integration

Description: This article will show you how to integrate phpBB3's sessions into your existing website.

In Categories:

Link to this article: Select All
[url=https://www.phpbb.com/support/docs/en/3.0/kb/article/phpbb3-sessions-integration/]Knowledge Base - phpBB3 Sessions Integration[/url]

phpBB3 Sessions Integration

Hello.

If you have an existing website, you may want to use phpBB3's sessions with your site. Why? Well, you can check to see if the user is logged in, what permissions the user has, and more. Note: this article is for integration into your existing site -- if you just need to make another web page that looks like phpBB3, see this article: Add a New Custom Page to phpBB

Let's get started.

Step 1

The first step in integrating phpBB3 into your site is to rename your existing file's extension (if necessary) to .php -- for example you would need to rename mypage.html to mypage.php Of course, this will break any existing links so be sure to update your links to point to the new mypage.php file.

Step 2

You will need to add this code at the top of every page you want to add phpBB's sessions into.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

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

Your existing page goes here


If you want access to a phpBB language file, then change this line:

Code: Select all

$user->setup();


to this:

Code: Select all

$user->setup('base-name-of-language-file-here');


Replace base-name-of-language-file-here with the name of the language file you want without the .php extension. For example, if you need to load the viewtopic.php language file, then use this code:

Code: Select all

$user->setup('viewtopic');


And that's all! Now you have full access to the phpBB sessions information.

Step 3 -- examples

Checking to see if a user is logged in

A very simple example to see if the user is logged in -- if he or she is logged in, a thank you message is displayed along with their username, but if they are not logged in, a message is displayed asking them to login.

Code: Select all

<?php
if ($user->data['user_id'] == ANONYMOUS)
{
   echo 'Please login!';
}

else
{
   echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>





Here's a list of all the user data variables you can access or check:

  • user_id - ID number of the user
  • user_type - 2
  • group_id - 1
  • user_permissions - 00000000003khra6tc
    i1cjyo000000
    i1cjyo000000
  • user_perm_from - 0
  • user_ip -
  • user_regdate - UNIX timestamp of the user's registration date
  • username - user's username
  • username_clean - clean version of the username
  • user_password - hashed password as outputted by the phpbb_hash() function
  • user_passchg - 0
  • user_pass_convert - 0
  • user_email - user's email address
  • user_email_hash - 0
  • user_birthday -
  • user_lastvisit - 0
  • user_lastmark - 0
  • user_lastpost_time - 0
  • user_lastpage -
  • user_last_confirm_key -
  • user_last_search - UNIX timestamp of the last search the user performed
  • user_warnings - total number of warnings
  • user_last_warning - UNIX timestamp of last warning
  • user_login_attempts - number of login attempts this session
  • user_inactive_reason - 0
  • user_inactive_time - 0
  • user_posts - total number of posts made by the user
  • user_lang - user's language
  • user_timezone - 0.00
  • user_dst - 0
  • user_dateformat - d M Y H:i
  • user_style - 1
  • user_rank - 0
  • user_colour -
  • user_new_privmsg - 0
  • user_unread_privmsg - 0
  • user_last_privmsg - 0
  • user_message_rules - 0
  • user_full_folder - -3
  • user_emailtime - 0
  • user_topic_show_days - 0
  • user_topic_sortby_type - t
  • user_topic_sortby_dir - d
  • user_post_show_days - 0
  • user_post_sortby_type - t
  • user_post_sortby_dir - a
  • user_notify - 0
  • user_notify_pm - 1
  • user_notify_type - 0
  • user_allow_pm - 1
  • user_allow_viewonline - 1
  • user_allow_viewemail - 1
  • user_allow_massemail - 0
  • user_options - 895
  • user_avatar -
  • user_avatar_type - 0
  • user_avatar_width - 0
  • user_avatar_height - 0
  • user_sig - the user's signature
  • user_sig_bbcode_uid -
  • user_sig_bbcode_bitfield -
  • user_from - user's location
  • user_icq - user's ICQ address
  • user_aim - user's AIM address
  • user_yim - user's Yahoo Messenger address
  • user_msnm - user's MSN Live address
  • user_jabber - user's Jabber address
  • user_website - user's website
  • user_occ - user's occupation
  • user_interests -
  • user_actkey -
  • user_newpasswd -
  • session_id - cf4eaea2eb0a0a1257bada05cd901ca7
  • session_user_id - 1
  • session_last_visit - UNIX timestamp of when the user last logged in
  • session_start - UNIX timestamp of when the user logged in
  • session_time - UNIX timestamp of the last time the user clicked on a page
  • session_ip - current IP address
  • session_browser - Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
  • session_forwarded_for -
  • session_page - test.php
  • session_viewonline - 1
  • session_autologin - 0
  • session_admin - 0
  • is_registered -
  • is_bot -





If you have any suggestions or find in bugs with this article, please send me a Private Message.

Enjoy :mrgreen: