{"id":18,"date":"2008-11-04T06:22:23","date_gmt":"2008-11-04T13:22:23","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=18"},"modified":"2008-11-04T06:22:23","modified_gmt":"2008-11-04T13:22:23","slug":"automated-member-registration-for-phpbb","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2008\/11\/04\/automated-member-registration-for-phpbb\/","title":{"rendered":"Automated member registration for phpBB"},"content":{"rendered":"<p>A lot of websites may require phpBB plugged-in as an add-on to the main site. In such a case if the main website already has a membership module in place, then it is desirable that when a member signups on the main website, he also becomes a member in phpBB.<\/p>\n<p>There are 3 ways of doing this:<\/p>\n<ol>\n<li>Manually redirect the user to the phpbb signup form  after signing up on the main site<\/li>\n<li>Do an automated form post in code to the phpbb registration page<\/li>\n<li>Add data to the phpbb database directly thus bypassing all the phpbb code<\/li>\n<li>Use phpbb functions to add the user to the phpbb database<\/li>\n<\/ol>\n<p>Method 1 is cumbersome and messy as the user is forced to enter his details twice- once for the main site and then for phpbb. This is not a very good option as you are making the user do all the dirty work for you.<\/p>\n<p>Method  2 is not possible with the latest version of phpBB (3.0 Olympus) as it requires Captcha authentication, unless you have a way of hacking the captcha code<\/p>\n<p>Method 3 is very undesirable as there are around 4 tables and 60 fields to update when a member signs up. Besides some of the fields like password etc are hashed using code internal to phpBb.<\/p>\n<p>Method 4 is the most seamless and safe.<\/p>\n<p>It just needs  3 fields to be prefilled: <span style=\"font-style: italic;\">username, user_password <\/span>and <span style=\"font-style: italic;\">user_email . <\/span>The rest of the fields are filled with default values by phpBB.<\/p>\n<p>The code is given below:<\/p>\n<hr \/>\n<pre>\n\n<div style=\"font-family: courier; color:black; font-size: 10px; background-color: #ffffd5; overflow-x: scroll;\">define('IN_PHPBB', true);\ndefine('ROOT_PATH', \"..\/pathtoforums\");\n\nif (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {\n\/\/exit();\n}\nelse {\n$phpEx = \"php\";\n$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '\/';\ninclude($phpbb_root_path . 'common.' . $phpEx);\ninclude($phpbb_root_path . 'includes\/functions_user.' . $phpEx);\n$arrTime = getdate();\n$unixTime = strtotime($arrTime['year'] . \"-\" . $arrTime['mon'] . '-' . $arrTime['mday'] . \" \" . $arrTime['hours'] . \":\" . $arrTime['minutes'] . \":\" . $arrTime['seconds']);\n\n$user_row = array(\n'username'              =&gt; $_GET['username'],\n'user_password'         =&gt; phpbb_hash($_GET['pwd']),\n'user_email'            =&gt; $_GET['email'],\n'group_id'              =&gt; (int) 2,\n'user_timezone'         =&gt; (float) 0,\n'user_dst'              =&gt; \"0\",\n'user_lang'             =&gt; \"en\",\n'user_type'             =&gt; 0,\n'user_actkey'           =&gt; \"\",\n'user_ip'               =&gt; $_SERVER['REMOTE_HOST'],\n'user_regdate'          =&gt; $unixTime,\n'user_inactive_reason'  =&gt; 0,\n'user_inactive_time'    =&gt; 0\n);\n\n\/\/ all the information has been compiled, add the user\n\/\/ tables affected: users table, profile_fields_data table, groups table, and config table.\n$user_id = user_add($user_row);                    }<\/div><\/pre>\n<hr \/>\n<p>It is assumed that the user data is being passed to this page via a GET. The most important thing is the define(ROOT_PATH) directive-it should point to the base directory of phpbb. Eg.if it is installed in \/phpbb then ROOT_PATH becomes \/phpbb.One thing to remember is that if the username is a duplicate one, then phpbb stops execution and shows the error page. Of course, the easiest way around this is the main site&#8217;s membership module which is taking care of userid validation, only then would the phpbb code called so its unlikely you will get a duplicate member error.<\/p>\n<p>&nbsp;<\/p>\n<p>Some pitfalls to avoid :<\/p>\n<ul>\n<li>If you integrate the code with other code in a page, you might get a class conflict error with <em>&#8216;class user&#8217; . <\/em>If you already have a class called user in your main code then it will conflict with phpbb&#8217;s user class.<\/li>\n<li>If you are directly opening a database connection in a page and then calling the above code in the same page, then you may get some runtime exceptions as it conflicts with the $db class of phpbb. The way around is this to capture the data in variables and then close and dispose all database classes before calling phpbb code.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>A lot of websites may require phpBB plugged-in as an add-on to the main site. In such a case if the main website already has <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2008\/11\/04\/automated-member-registration-for-phpbb\/\" title=\"Automated member registration for phpBB\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[36,45,50,180,200,204,218,219,257],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-apachephp","tag-amit","tag-automated","tag-bb","tag-member","tag-php","tag-phpbb","tag-register","tag-registration","tag-truelogic"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}