MathewHood Posted December 23, 2009 Share Posted December 23, 2009 Hey everyone, I have managed to get the code to enter the user into the database. I had to comment out the user image input thing because it wasn't working, and also the verification e-mail i don't think is quite working but these don't bother me. The "issue" with my code is best shown in these two screenshots: http://img692.imageshack.us/img692/1127/register1.jpg - Entering registration data http://img686.imageshack.us/img686/4214/register2.jpg - After registering Here is my code, I am not sure how to make it so instead of showing the phpBB page, it can just like... echo "Thankyou for registering, your account has been created. You may now log in with your username and password."; Here is my source code" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="styles/default.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Simul-Tech Website</title> <script type="text/javascript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> </head> <body onload="MM_preloadImages('images/product_over.png','images/contactus_over.png','images/forum_over.png','images/blog_over.png')"> <center> <div class="container"> <div class="masthead"><a href="#"><img src="images/logo.png" alt="logo" width="258" height="100" border="0" align="left" /></a> <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contactus','','images/contactus_over.png',1)"><img src="images/contactus.png" alt="contactus" name="contactus" width="92" height="94" border="0" align="right" id="contactus" /></a> <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('forum','','images/forum_over.png',1)"><img src="images/forum.png" alt="forum" name="forum" width="91" height="94" border="0" align="right" id="forum" /></a> <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('products','','images/product_over.png',1)"><img src="images/product.png" alt="products" name="products" width="91" height="94" border="0" align="right" id="products" /></a> <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('blog','','images/blog_over.png',1)"><img src="images/blog.png" alt="blog" name="blog" width="91" height="94" border="0" align="right" id="blog" /></a> </div> <div class="subcontainer"> <div class="login"> <?php include "errorreport.php"; session_start(); if($_SESSION['username']){ echo "Welcome, ".$_SESSION['username']." !<a href='logout.php'>Logout</a>"; } else { ?> <form action="login.php" method="POST"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> <input type="submit" value="Login" /> Not a member? <a href="register.php">Click here</a> to register. </form> <?php } ?> </div> <div class="search"> <form action="search.php" method="get"> <input type="text" name="search"> <input type="submit" name="submit" value="Search"> </form> </div> </div> <div class="maincontainer"> <div class="contentcontainer"> <div class="contentheader"> <img src="images/simultech.png" align="right" /> </div> <div class="content"> <?php // connect to database $connect = mysql_connect("localhost","root",""); mysql_select_db("phpbb"); define('IN_PHPBB', true); $phpbb_root_path = './phpBB3/'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'includes/functions_display.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup('ucp'); if($user->data['is_registered']) { meta_refresh(3, append_sid("index.$phpEx")); trigger_error("You are already registered."); } if ($config['require_activation'] == USER_ACTIVATION_DISABLE) { trigger_error('UCP_REGISTER_DISABLE'); } $confirm_id = request_var('confirm_id', ''); $submit = (isset($_POST['submit'])) ? true : false; // Check and initialize some variables if needed if ($submit) { $error = $cp_data = $cp_error = array(); $data = array( 'username' => utf8_normalize_nfc(request_var('username', '', true)), 'new_password' => request_var('new_password', '', true), 'password_confirm' => request_var('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'email_confirm' => strtolower(request_var('email_confirm', '')), //'confirm_code' => request_var('confirm_code', ''), ); $error = validate_data($data, array( 'username' => array( array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', '')), 'new_password' => array( array('string', false, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', false, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array( array('string', false, 6, 60), array('email')), 'email_confirm' => array('string', false, 6, 60), //'confirm_code' => array('string', !$config['enable_confirm'], 5, , )); // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); // DNSBL check if ($config['check_dnsbl']) { if (($dnsbl = $user->check_dnsbl('register')) !== false) { $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]); } } // Visual Confirmation handling /*$wrong_confirm = false; if ($config['enable_confirm']) { if (!$confirm_id) { $error[] = $user->lang['CONFIRM_CODE_WRONG']; $wrong_confirm = true; } else { $sql = 'SELECT code FROM ' . CONFIRM_TABLE . " WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . CONFIRM_REG; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { if (strcasecmp($row['code'], $data['confirm_code']) === 0) { $sql = 'DELETE FROM ' . CONFIRM_TABLE . " WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . CONFIRM_REG; $db->sql_query($sql); } else { $error[] = $user->lang['CONFIRM_CODE_WRONG']; $wrong_confirm = true; } } else { $error[] = $user->lang['CONFIRM_CODE_WRONG']; $wrong_confirm = true; } } }*/ if (!sizeof($error)) { if ($data['new_password'] != $data['password_confirm']) { $error[] = $user->lang['NEW_PASSWORD_ERROR']; } if ($data['email'] != $data['email_confirm']) { $error[] = $user->lang['NEW_EMAIL_ERROR']; } } if (!sizeof($error)) { $server_url = generate_board_url(); // Which group by default? $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED'; $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $db->sql_escape($group_name) . "' AND group_type = " . GROUP_SPECIAL; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error('NO_GROUP'); } $group_id = $row['group_id']; if (($coppa || $config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable']) { $user_actkey = gen_rand_string(10); $key_len = 54 - (strlen($server_url)); $key_len = ($key_len < 6) ? 6 : $key_len; $user_actkey = substr($user_actkey, 0, $key_len); $user_type = USER_INACTIVE; $user_inactive_reason = INACTIVE_REGISTER; $user_inactive_time = time(); } else { $user_type = USER_NORMAL; $user_actkey = ''; $user_inactive_reason = 0; $user_inactive_time = 0; } // Set Timezone = EST $data['tz'] = -5.00; $user_row = array( 'username' => $data['username'], 'user_password' => phpbb_hash($data['new_password']), 'user_email' => $data['email'], 'group_id' => (int) $group_id, 'user_timezone' => (float) $data['tz'], 'user_dst' => $is_dst, 'user_lang' => $data['lang'], 'user_type' => $user_type, 'user_actkey' => $user_actkey, 'user_ip' => $user->ip, 'user_regdate' => time(), 'user_inactive_reason' => $user_inactive_reason, 'user_inactive_time' => $user_inactive_time, ); // Register user... $user_id = user_add($user_row, $cp_data); // This should not happen, because the required variables are listed above... if ($user_id === false) { trigger_error('NO_USER', E_USER_ERROR); } if ($coppa && $config['email_enable']) { $message = $user->lang['ACCOUNT_COPPA']; $email_template = 'coppa_welcome_inactive'; } else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable']) { $message = $user->lang['ACCOUNT_INACTIVE']; $email_template = 'user_welcome_inactive'; } else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable']) { $message = $user->lang['ACCOUNT_INACTIVE_ADMIN']; $email_template = 'admin_welcome_inactive'; } else { $message = $user->lang['ACCOUNT_ADDED']; $email_template = 'user_welcome'; } if ($config['email_enable']) { include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); $messenger = new messenger(false); $messenger->template($email_template, $data['lang']); $messenger->to($data['email'], $data['username']); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->assign_vars(array( 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 'USERNAME' => htmlspecialchars_decode($data['username']), 'PASSWORD' => htmlspecialchars_decode($data['new_password']), 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey") ); if ($coppa) { $messenger->assign_vars(array( 'FAX_INFO' => $config['coppa_fax'], 'MAIL_INFO' => $config['coppa_mail'], 'EMAIL_ADDRESS' => $data['email']) ); } $messenger->send(NOTIFY_EMAIL); if ($config['require_activation'] == USER_ACTIVATION_ADMIN) { // Grab an array of user_id's with a_user permissions ... these users can activate a user $admin_ary = $auth->acl_get_list(false, 'a_user', false); $admin_ary = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array(); // Also include founders $where_sql = ' WHERE user_type = ' . USER_FOUNDER; if (sizeof($admin_ary)) { $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary); } $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type FROM ' . USERS_TABLE . ' ' . $where_sql; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $messenger->template('admin_activate', $row['user_lang']); $messenger->to($row['user_email'], $row['username']); $messenger->im($row['user_jabber'], $row['username']); $messenger->assign_vars(array( 'USERNAME' => htmlspecialchars_decode($data['username']), 'U_USER_DETAILS' => "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id", 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey") ); $messenger->send($row['user_notify_type']); } $db->sql_freeresult($result); } } $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>'); trigger_error($message); } } $s_hidden_fields = array( 'agreed' => 'true', 'change_lang' => 0, ); $s_hidden_fields = build_hidden_fields($s_hidden_fields); $confirm_image = ''; // Visual Confirmation - Show images /*if ($config['enable_confirm']) { if ($change_lang) { $str = '&change_lang=' . $change_lang; $sql = 'SELECT code FROM ' . CONFIRM_TABLE . " WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . CONFIRM_REG; $result = $db->sql_query($sql); if (!$row = $db->sql_fetchrow($result)) { $confirm_id = ''; } $db->sql_freeresult($result); } else { $str = ''; } if (!$change_lang || !$confirm_id) { //$user->confirm_gc(CONFIRM_REG); $sql = 'SELECT COUNT(session_id) AS attempts FROM ' . CONFIRM_TABLE . " WHERE session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . CONFIRM_REG; $result = $db->sql_query($sql); $attempts = (int) $db->sql_fetchfield('attempts'); $db->sql_freeresult($result); if ($config['max_reg_attempts'] && $attempts > $config['max_reg_attempts']) { trigger_error('TOO_MANY_REGISTERS'); } $code = gen_rand_string(mt_rand(5, ); $confirm_id = md5(unique_id($user->ip)); $seed = hexdec(substr(unique_id(), 4, 10)); // compute $seed % 0x7fffffff $seed -= 0x7fffffff * floor($seed / 0x7fffffff); $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array( 'confirm_id' => (string) $confirm_id, 'session_id' => (string) $user->session_id, 'confirm_type' => (int) CONFIRM_REG, 'code' => (string) $code, 'seed' => (int) $seed) ); $db->sql_query($sql); } $confirm_image = '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&id=' . $confirm_id . '&type=' . CONFIRM_REG . $str) . '" alt="" title="" />'; $s_hidden_fields .= '<input type="hidden" name="confirm_id" value="' . $confirm_id . '" />'; }*/ // $l_reg_cond = ''; switch ($config['require_activation']) { case USER_ACTIVATION_SELF: $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE']; break; case USER_ACTIVATION_ADMIN: $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE']; break; } if( isset($error)) { $error_display = (sizeof($error)) ? implode('<br />•', $error) : ''; echo '<p>'.$error_display.'</p>'; } ?> <form action="register2.php" method="post"> <table width="100%" align="center"> <tbody> <tr align="center"> <td width="30%" align="left"><label for="username">Desired Username: </label></td> <td width="70%" align="left"><input id="username" type="text" size="25" maxlength="50" name="username" /></td> </tr> <tr align="center"> <td width="30%" align="left"><label for="email">E-mail Address: </label></td> <td width="70%" align="left"><input id="email" type="text" size="25" maxlength="100" name="email" /></td> </tr> <tr align="center"> <td width="30%" align="left"><label for="email_confirm">Confirm E-Mail Address: </label></td> <td width="70%" align="left"><input id="email_confirm" type="text" name="email_confirm" size="25" maxlength="100" /></td> </tr> <tr align="center"> <td width="30%" align="left"><label for="new_password">Password: </label></td> <td width="70%" align="left"><input id="new_password" type="password" size="25" maxlength="50" name="new_password" /></td> </tr> <tr align="center"> <td width="30%" align="left"><label for="password_confirm">Confirm Password: </label></td> <td width="70%" align="left"><input id="password_confirm" type="password" size="25" maxlength="50" name="password_confirm" /></td> </tr> <!--<tr align="center"> <td width="30%" align="left">Confirmation Image: </td> <td width="70%" align="left"><?= $confirm_image ?><?= $s_hidden_fields ?></td> </tr> <tr align="center"> <td width="30%" align="left"> </td> <td width="70%" align="left"><input type="text" name="confirm_code" size="25" maxlength="8" /></td> </tr> <tr align="center"> <td class="note" width="30%" align="left"> </td> <td width="70%" align="left"><span class="note">Enter the code exactly as it appears. <br />All letters are case insensitive, there is no zero.</span></td> </tr>--> </tbody> </table> <table width="100%" align="center"> <tbody> <tr align="center"> <td width="100%" align="center"><input type="submit" name="submit" value="Submit" /></td> </tr> </tbody> </table> </form> </div> </div> </div> <div class="rightcontainer"> <div class="blogcontainer"> <div class="blogheader"> <img src="images/recentblogs.png" align="right" /> </div> <div class="blogcontent"> </div> </div> <div class="forumcontainer"> <div class="forumheader"> <img src="images/recentthreads.png" align="right" /> </div> <div class="forumcontent"> </div> </div> <div class="networkscontainer"> <div class="networks"> <img src="images/Linked In-32.png" align="center" /> </div> </div> </div> </div> </div> </center> </body> </html> The main php code is within the <div class="content"> Link to comment https://forums.phpfreaks.com/topic/186121-external-php-registration/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.