I have found that most of the time when you register in a website, you'll need to register for the phpBB forum separately! This is really disgusting for the user... So here's a php script which will register the user with phpBB! All you need to do is the following steps...
1) First Create a file named config.php and copy the following code to it
Code: Select all
<?php
$conn=mysql_connect("localhost","root","password")//change the password to suit yours
or die("mysql_error()");
$db=mysql_select_db("mysite_db")//change mysite_db to your database name
or die(mysql_error());
?>2)Now create the main file preferably index.php or register.php and copy the following code
Code: Select all
<?php
/**
Description: This is an example of the function which can be used to register your site user with the phpBB forum when he/she registers with your custom registration procedure. The function is very simple. You just need to supply the username,password(not encrypted, because the code does it) and the email, the rest is done by the code. Remember that you need to validate the e-mail yourself using custom code. You can use the activate_user function to activate the user after the email has been verified.
Keep in mind that I consider that you have not given automatic account activation. If you have given there is no need to use the activate _user function. But I would reccomend you to not use automatic activation.
If you encounter any problem feel free to ask at http://www.devunite.com
*/
include "config.php"; // the database configuration file. Update this to connect to your databse
function register_phpBB($username,$user_password,$user_email){
//fucntion to regiter with phpBB
//find the next userid
$query="select max(user_id) as total from phpbb_users";
$results=mysql_query($query) or die(mysql_error());
if($results){
$row=mysql_fetch_row($results);//store the result in $row array
$user_id=++$row['0'];//increment the currnet user_id by 1
}
//encrypt the password using md5
$enc_password=md5($user_password);
mysql_free_result($results);//free the result
//insert new registration details to database
$query="insert into phpbb_users(user_id,username,user_regdate,user_password,user_email)";
$query=$query."values('".$user_id."','".$username."',".time().",'".$enc_password."','".$user_email."')";
$results=mysql_query($query) or die(mysql_error());
if($results){
echo "Successfully registered with phpBB";
return 1;
}else{
echo "Registration failed";
return 0;
}
}
//function to activate the user. Give the user id as the parameter.
function activate_user($user_id){
$query="update phpbb_users set user_active=1 where user_id=".$user_id;
$results=mysql_query($query) or die(mysql_error());
if(!$results){
echo "The account has been activated!";
}
}
//check if the form was submitted
if((isset($_POST['Submit']) && $_POST['Submit']=="Register")){
//check whether the username and e-mail already exist or not
$sql="select username,user_email from phpbb_users where username='".$_POST['username']."' or user_email='".$_POST['email']."'";
$results=mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($results)>0){
$row=mysql_fetch_row($results);
if($_POST['username']==$row['0']){//check the username
echo "Username already taken!";
}elseif($_POST['email']==$row['1']){//checks the e-mail
echo "The e-mail already used for registration!";
}else{//username and e-mail not used
//register new user to access phpBB forum
register_phpBB($_POST['username'],$_POST['password'],$_POST['email']);
}
}else{
//register new user to access phpBB forum
register_phpBB($_POST['username'],$_POST['password'],$_POST['email']);
}
}else{
?>
<!---- the form to take input ----!>
<html>
<body>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" value="username" align="LEFT" name="username" />
<br>
<input type="password" value="password" name="password" />
<br>
<input type="text" value="email" name="email" />
<br>
<input type="submit" value="Register" name="Submit" />
</form>
</body>
</html>
<?
}
?>I wish you'll find this tutorial useful!