Integrating punbb registration with your web application
PunBB is a free/open source discussion board built on PHP and MySQL. Because it is lightweight and fast, it is my favorite.
Usually in a website, you have a database of users administered by your own applications. When you decide to add, say a forum like punBB or phpBB, users have to register separately for that forum. Then, if you add a blog like this powered by wordpress, users will have to register for a third time. This is irritating on the users’ side. This is not a good design too. In this post, I intend to describe how I integrated punbb with my web application.
I have a database of users and I want them to be able to use the punbb forums hosted on my server with the same username and password.
- On my root directory, I have my register.php file through which users can register on my website. In the same level as register.php, I have a “myforum” directory where I have uploaded the files of punbb.
- When users register on register.php, I want them to be automatically registered for the punbb forums as well.
- The register.php takes some values from POST method. The variables “username”, “password” and “email” contain the username, password and email respectively supplied by the user through a html form.
- While installing punbb, I had entered “pun_” as the prefix for its tables. So, I have a table named “pun_users” on my database. I already have “users” table for my application.
This is what I did:
<?php
/*---- file: register.php ----*/
include "myforum/include/functions.php"; /*for the pun_hash function to work*/
$dbhost="localhost"; /*the name of my database host*/
$dbusr="bibek"; /*my mysql database username*/
$dbpass="paudel"; /*my mysql database password*/
$dbname="example"; /*name of my mysql database*/
$connection = mysql_connect($dbhost, $dbusr, $dbpass)
or die(mysql_error());
$dbhandle = mysql_select_db($dbname, $connection)
or die(mysql_error());
$usrname=$_POST['username'];
$password=pun_hash($_POST['password']);
$email=$_POST['email'];
$regdate = strtotime ("now"); /*generates UNIX timestamp of current time*/
$groupid = "4"; /*groupid 4 is for normal members of punbb*/
$language = "English";
$timezone = "5.45"; /*assuming all users are from Nepal*/
$punbb_query="INSERT into pun_users (group_id, registered, username, password, email, language, timezone) values ('$groupid','$regdate','$usrname','$password','$email','$language','$timezone')";
$mydb_query="INSERT into users (username,password,email) values('$usrname','$password','$email')";
((mysql_query($punbb_query,$connection)) && (mysql_query($mydb_query,$connection)))
or die ("Couldn't register you..");
?>
A look at the description of the pun_users table will provide you more customizable features but this much will just do your job.
I think that’s all.




great start! thanks for the share
madewira
April 21, 2008 at 9:13 pm
Topic for spam?
TommyUI
January 12, 2009 at 12:56 pm
This is quite a hot info. I’ll share it on Digg.
Jane Goody
April 22, 2009 at 12:58 pm