Firefox PHP

Register integration

Posted by GC PoseidoN 
Register integration
May 07, 2009 12:02AM
Hey guys, just found this script and I'm loving it. However, I am a total noob when it comes to MySQL and PHP and I can't figure this out.

My Phorum tables are in the same database as my CMS and the prefix is phorum.

What I want to do is basically make it so when someone signs up for the main site they sign up for the forums too. I don't need anything fancy, just the Username, password and e-mail.

Here's my default register page without the integration.

Language: PHP
session_start(); include("./includes/incglobal.php");   switch($action){   case "joinb": addmember($member); break;   case "activate": activate(); break;   default: newteam($team); break; }     function newteam($team){ global $config;   if(isset($_COOKIE["user"])){ $out[body].="<br /><center> <table width=';90%'; border=';0'; cellspacing=';1'; cellpadding=';1'; bgcolor=';#00000';> <tr bgcolor=';$config[altcolora]';> <td width=';100%'; valign=';center'; align=';left'; colspan=';2'; background=';$config[bg]';> <strong>Join Ladder</strong> </td> </tr> <tr bgcolor=';$config[altcolorb]';> <td width=';100%'; valign=';center'; align=';left';><center> <b>You are already registered!<br /> [<a href=';./login.php?act=logout';>Logout</a>]</center></td></tr> </table> </center><br /><br /><br /><br />";   include("$config[html]"); exit; }   $out[body].="<script type=';text/javascript'; src=';./js/pwds.js';></script> <br /> <center> <table width=';90%'; border=';0'; cellspacing=';1'; cellpadding=';2'; bgcolor=';#000000';> <form method=';post';> <tr bgcolor=';$config[altcolora]';> <td width=';100%'; valign=';center'; background=';$config[bg]'; align=';center'; colspan=';2';> <strong>New Member Signup</strong><br></td> </tr> <tr bgcolor=';$config[altcolorb]';> <td width=';40%'; valign=';center'; align=';left'; background=';$config[cellbg]';>*Username</td> <td width=';60%'; valign=';center'; align=';center'; background=';$config[cellbg]';><input type=';text'; name=';member[name]'; value=';$member[name]'; class=';input'; size=';40'; maxlength=';15';></td> </tr> <tr bgcolor=';$config[altcolora]';> <td width=';40%'; valign=';center'; align=';left'; background=';$config[cellbg2]';>*Email</td> <td width=';60%'; valign=';center'; align=';center'; background=';$config[cellbg2]';><input class=';input'; type=';text'; name=';member[email]'; value=';$member[email]'; size=';40'; maxlength=';40';></td> </tr> <tr bgcolor=';$config[altcolorb]';> <td width=';40%'; valign=';center'; align=';left'; background=';$config[cellbg]';>*Password</td> <td width=';60%'; valign=';center'; align=';center'; background=';$config[cellbg]';><input class=';input'; type=';password'; name=';member[pass]'; value=';'; size=';40'; maxlength=';20'; onkeyup=\"runPassword(this.value, ';mypassword';);\"> <div style=';width: 100px;';> <div id=';mypassword_text'; style=';font-size: 10px;';></div> <div id=';mypassword_bar'; style=';font-size: 1px; height: 2px; width: 0px;';></div> </div></td> </tr> <tr bgcolor=';$config[altcolora]';> <td width=';40%'; valign=';center'; align=';left'; background=';$config[cellbg2]';>*Password Again</td> <td width=';60%'; valign=';center'; align=';center'; background=';$config[cellbg2]';><input class=';input'; type=';password'; name=';member[passa]'; value=';'; size=';40'; maxlength=';20';></td> </tr> <tr bgcolor=';$config[altcolora]';> <td width=';40%'; valign=';center'; align=';left'; background=';$config[cellbg]';>*Country</td> <td width=';60%'; valign=';center'; align=';center'; background=';$config[cellbg]';> <select name=';member[country]'; class=';button';> <option value=';US';>United States </select></td></tr> <tr bgcolor=';$config[altcolorb]';> <td width=';40%'; valign=';center'; background=';$config[cellbg2]'; align=';left';>Gender</td> <td width=';60%'; valign=';center'; background=';$config[cellbg2]'; align=';center';> <select name=';member[gender]'; class=';button';> <option value=';';>Select One...</option> <option value=';Male'; >Male</option> <option value=';Female'; >Female</option> </select></td></tr> <tr bgcolor=';$config[altcolora]';> <td width=';40%'; valign=';center'; align=';center';><img src=';./includes/captcha.php'; /></td> <td width=';60%'; valign=';center'; align=';center';>Enter the text you see in the image. (Leave this blank.)<br /><input class=';input'; type=';text'; name=';member[capt]'; value=';'; size=';40'; maxlength=';13';></td> </tr> <tr bgcolor=';$config[altcolorb]';> <td width=';100%'; valign=';center'; align=';center'; colspan=';2'; background=';$config[cellbg]';><input class=';button'; type=';checkbox'; name=';member[agree]'; value=';yes';> I am at least 13 years of age</td> </tr> <tr bgcolor=';$config[altcolora]';> <td width=';100%'; valign=';top';'; align=';center'; colspan=';2'; background=';$config[cellbg2]';> <input type=';hidden'; name=';action'; value=';joinb';> <input type=';submit'; class=';button'; name=';submit'; value=';Create Account';></td> </form> </tr> </table> </center><br /><br /><br /><br />";   include("$config[html]"); }     function addmember($member){ global $config;   if($member[agree] <> yes){ $mes.="You must be 13 years of age to join.<br />"; }   $ip=getenv("REMOTE_ADDR");   if(mysql_num_rows(mysql_query("SELECT ipaddress FROM members WHERE ipaddress=';$ip';"))){ $mes.="You are already an active member.<br>"; error($mes); } if(!$member[name]){ $mes.="You must enter a username.<br />"; } if(!$member[pass]){ $mes.="You must enter a username.<br />"; }   if($member[pass] <> $member[passa]){ $mes.="Your passwords do not match. <br />"; } include("./includes/check.php");   $member[name]=charecters($member[name]); $member[email]=charecters($member[email]); $member[pass]=charecters($member[pass]);     if(mysql_num_rows(mysql_query("SELECT id FROM members WHERE name=';$member[name]';"))){ $mes.="This name is already in use.<br />"; } if(mysql_num_rows(mysql_query("SELECT id FROM members WHERE email=';$member[email]';"))){ $mes.="This email is already in use.<br />"; } if(!$member[country]){ $mes.="You must enter a country.<br />"; } if ($_SESSION["capt"] <> $member[capt]) { $mes.="The text you entered for verification was wrong."; } if($mes){ error("$mes"); }   $enurl = md5($member[name]); $pass2 = md5(md5($member[pass]));   $fields=mysql_query("SELECT id FROM customfields"); while(list($id)=mysql_fetch_row($fields)){ $extrasql.=",';';"; }   if($config[emailactivation] == yes){ $anumber="0"; $atext="You must activate your account by clicking the following link.<br /> $config[sitelink]/register.php?action=activate&hash=$enurl"; $atext2="You must activate your account by clicking the link provided in your email, you have five days to do so."; }else{ $anumber="1"; $atext="Your account is now active."; $atext2="Your account is now active."; }   mysql_query("INSERT INTO members VALUES ( NULL, ';$member[name]';, ';$ip';, ';$enurl';, ';$member[gender]';, ';$member[country]';, ';$pass2';, ';$member[email]';, ';';, ';http://';, ';';, ';';, ';';, ';';, ';';, ';http://';, ';';, ';2';, NULL, ';$anumber'; $extrasql)");   $out[body].=" <br /><center> <table width=';90%'; border=';0'; cellspacing=';1'; cellpadding=';2'; bgcolor=';000000';> <tr bgcolor=';$config[altcolor]';> <td width=';100%'; background=';$config[bg]'; valign=';center'; align=';center'; colspan=';5';><b>Welcome to $config[sitename]</b></td> </tr> <tr bgcolor=';$config[altcolor]';> <td width=';100%'; valign=';center'; align=';center'; colspan=';5';>Welcome to $config[sitename],<br> Your username is <b>$member[name]</b>.<br /> $atext2</td> </tr> </table></center><br /><br /><br /><br />";   $email[toname] ="$member[name]"; $email[toemail] ="$member[email]"; $email[subject] ="Welcome to $config[sitename]"; $email[fromname] ="$config[sitename]"; $email[fromemail] ="$config[sitemail]"; $email[replyname] ="$member[name]"; $email[replyemail] ="$member[email]"; $email[body] ="Hello $member[name],\n   Welcome to $config[sitename]! Your new account info is below, be sure to write it down, or store it somewhere.   Your Account Username is: $member[name] Your Password is: $member[pass]   $atext   $config[sitename] $config[sitelink]";   email($email);   include("$config[html]"); }     function activate(){ global $config;   if(!mysql_num_rows(mysql_query("SELECT id FROM members WHERE salt=';{$_GET[';hash';]}'; AND act=';0';"))){ error("Invalid Activation Link"); }   mysql_query("UPDATE members SET act=';1'; WHERE salt=';{$_GET[';hash';]}'; AND act=';0';");   $out[body].=" <META HTTP-EQUIV=';refresh'; content=';60;URL=$config[scripturl]/login.php';> <br /><center> <table width=';90%'; border=';0'; cellspacing=';1'; cellpadding=';2'; bgcolor=';000000';> <tr bgcolor=';$config[altcolor]';> <td width=';100%'; background=';$config[bg]'; valign=';center'; align=';center'; colspan=';5';><b>Account Activated!</b></td> </tr> <tr bgcolor=';$config[altcolor]';> <td width=';100%'; valign=';center'; align=';center'; colspan=';5';>Welcome to $config[sitename],<br> Your account is now activated! You may now <a href=';./login.php';><i>login</i></a>. It is then suggested to visit the <a href=';./manager.php';>Manager</a> and edit your account info.</td> </tr> </table></center><br /><br /><br /><br />";   include("$config[html]"); } ?>

Now I figure submitting the inputs to the database has something to do with this... but how would I edit this to work for phorum???

Language: PHP
mysql_query("INSERT INTO members VALUES ( NULL, ';$member[name]';, ';$ip';, ';$enurl';, ';$member[gender]';, ';$member[country]';, ';$pass2';, ';$member[email]';, ';';, ';http://';, ';';, ';';, ';';, ';';, ';';, ';http://';, ';';, ';2';, NULL, ';$anumber'; $extrasql)");

I'm really lost with this... I'm a total PHP noob.
Re: Register integration
May 07, 2009 08:26AM
It would be best to let Phorum's code handle the creation of the Phorum user. You should include the common.php file (which will bring the necessary db and api files) and use the phorum_api_user_save() function.

So, your addmember() function would:
  • Save the current working directory and change the working directory to the Phorum root.
  • include the common.php file
  • run checks on the Phorum username and email address for duplicates (using the phorum_api_user_search() function)
  • create the user with the phorum_api_user_save() function
  • grab the returned Phorum user_id and store this in your site's database
  • return to your original working directory
Your activate() function would:
  • Save the current working directory and change the working directory to the Phorum root.
  • include the common.php file
  • grab the activated user's Phorum user_id from your site's database
  • use the phorum_api_user_save() function with that user_id to set the user to active in Phorum as well
  • return to your original working directory

I would recommend checking out the code in my External Authentication module's base plugin (in particular the hook_user_session_restore.php file) as many of the steps above are demonstrated in that code.


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Register integration
May 07, 2009 04:22PM
If your application also generates a user id number, you can pass that to the phorum_api_user_save() function also. (ie phorum does not need to generate the id number)
Sorry, only registered users may post in this forum.

Click here to login