phpBB3 + site integration.

Post all your tuts or request for tuts here.
Post Reply
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

phpBB3 + site integration.

Post by Torniquet »

Ok long time since i done one of these :p

in this quick tutorial, i am going to go through some quick steps to using phpBB as a foothold for a full member based website (could easily be used in a game aswell)

I will follow up on these in due time, but as it stands, i am still learning and will most likly be developing my main site using said methods (purly because i really cnt be bothered to build a forum from the ground up lol)

and even if i dont use this method in building my website, its still a nice learning experience :)

please take heed of the following note...

I am not an expert phpbb modder, nor am i very experienced in using the phpbb functions, methods or otherwsise when it comes to website intergration.

so please dont ask me how to do things involving phpbb to get things done :p

if you would like to know how to do something, by all means ask... but it doesnt mean it will get answered straight away (if at all)

final note, please no silly questions on why your code is not working, when i have placed the code in pure black and white and knowing it works. i am only showing and going through what i know works.

none of the following is self discovered. it is all taken from various sources and put together.

Love yall xx

Quick reference.

for the perpous to this tutorial. i will refer to root as being my root directory, forum as my forum directory and include as my include directory.
(your files and folders do not have to match mine, just make sure you remember what they are and where they are)

Structure.

Root;
forum;
include;

Step 1) PHPBB install

the most simplest. download phpbb3 and install. i am not going to go through the steps as it is on the main phpbb website.

Step 2) The include file

create a new php file and call it 'phpbb.php' and put it in the include folder.

enter the following code in the above file.

Code: Select all

define('IN_PHPBB', true);
$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();
NOTE: $phpbb_root_path = './forum/'; make sure this matches your forum directory name.

this file will get all information from the database that will match your user.


Step 3) Index page start

Start a new php file named 'index.php' this is to be saved in root directory.

for this we will show either the login form or the users name in the colour it would display on the forum (admin=red, mod=green etc) then followed by the number of posts that the user has made.

to start off with we want to include the file we have just made 'phpbb.php'.

Code: Select all

<?php
require_once 'include/phpbb.php';
?>
once we have included that file (or required in this case), we need to find out whether the user is logged in or not. we do this by finding out if the player is registered.

add the following inside the php tags.

Code: Select all

if($user->data['is_registered']){
//Logged in
} else {
//Not logged in
}
Step 4) Not logged in

we will now build the login form and allow you to log into the forum from the index page. (it will direct you to the board index. please see the Optionals section at the end of the tutorial)

start with the standard form tags, setting the method to post and action to ./forum/ucp.php?mode=login, then create your input text fields and submit button. the names will remain blank for a minute. This code needs to go in the 'else' condition

Code: Select all

echo '<form action="./forum/ucp.php?mode=login" method="post">'
echo 'Username: <input type="text" name=""><br />';
echo 'Password: <input type="password" name=""><br />';
echo '<input type="submit" value="Login" name="">
echo '</form>';
we have now built the basics for our form for the users to log into. We will now fill in the name attributes to the input tags.

username -> name="username"
password -> name="password"
submit button -> name="login"

providing you have done all this correctly, you will now be able to log into your forum using users already listed in the database. Give it a try :)

for the next step, you will need to be logged in and back on your index page.

Step 5) Logged in

this is where we will put the information to display the users name, in the colour of their group (admin, mod etc) and display the number of posts.
for fun we will also put in a link to the forum, and a log out link.

to start with we will display the users name and colour.

in the if condition add the following code.

Code: Select all

echo 'logged in as <font color="#' . $user->data['user_colour'] . '">' . $user->data['username'] . '</font>';
by using $user->data[' '], we are pulling information from the users table in the database. in this case, we are using 'user_colour' and 'username'
user_colour is getting the hex colour code for the username to be displayed in. Note: you must insert the # symbol before concatenating the user_colour information. this is not displayed in the database field. if you do not add it, it will not work.

next we will display the number of posts the user has made. for this we will be using the table field 'user_posts'

Code: Select all

echo '<br />';
echo 'You have posted ' . $user->data['user_posts'] . ' time(s)!';
echo '<br />';
now if you refresh the page, you should notice that your username comes up and the amount of posts is also displayed.

Now for the last bit, the link to the forum, and the link to log out.
obviously the link to the forum is a bog standard link, the logout link is slightly different, and we will need a phpbb function to do it.

the function we will be using is the append_sid() function. this adds the users session id onto the end of any link.

ok for the easy one. a simple a tag with href, but to make it seem abit more complicated... we will use a defined variable made on the include file ;)

Code: Select all

echo '<a href="' . $phpbb_root_path . '">To the forum</a>';
echo '<br />';
Done :D

now for the last link. like i said we will need to use a phpbb function for this one.

Code: Select all

echo '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id) . '">Log out</a>';
now by clicking that link, it will log you out.

Note: you will be taken back to the board index apon loging out. See optional section to change this.



Optionals section) adjusting refreshes.

The first one is a simple one. when you log in, you are taken directly to the board index. to make it take you back to the index page after logging in, add this hidden input tag inside the login form (above the login button)

Code: Select all

echo '<input type="hidden" name="redirect" value="../index.php">';
where it says value, enter the name of the page you want it to direct you to.


changing the logout redirect.

This one is abit trickier, as you need to edit the accual phpbb files.

Direct yourself and open up the ucp.php file, locatied in the forum directory.

on line 95, you will see a meta_refresh command. meta_refresh(3, some value for the page) i cant remmeber what it was becaus ei edited mine :p

change that page value to '../index.php'

now when you log in and out you wil be directed to your index page.

have fun with it, good luck.

feel free to ask any questions.. just dont ask me how to do things that isn't displayed in this post. I am playing about with this inbetween work and my game. so :p to be honest :)

i will post more tutorials based around this as and when i get time.
New Site Coming Soon! Stay tuned :D
Post Reply

Return to “Tutorials”