PHPBB3 Website Intergrating systems.

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

Re: PHPBB3 Website Intergrating systems.

Postby topdown » 05 Dec 2008, 15:59

You guys are going about this wrong,

Files in the forum system or site that uses it should not look like you can't make up your mind on a code language.
It may be OK elsewhere, but not with phpBB 3.

3 files,
PHP page to generate the content for the actual page
PHP language page for your PHP language vars
HTML template in your styles templates to display the data for browsers

Here is a wiki article on additional pages
http://wiki.phpbb.com/Add_custom_page

If you are using some other system (CMS) here is an external login article
http://wiki.phpbb.com/External_Login

But if you are using phpBB3 for the whole thing, follow the tutorials.
No matter what login is going to go through redirects to get the job done.

You can make the login go through something else like /site/login.php (which is like my site)
But it will require extra coding and another directory, and you will still have a redirect.
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3021
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9


Re: PHPBB3 Website Intergrating systems.

Postby Robbie Garrett » 14 Jun 2012, 08:56

Hello,

Been a while since I last came on here, as the project I was doing got the plug pulled by the owner - but I am back with a massive project hopefully getting a user CMS going using the phpbb forums.

I have all my old files, so it helps me get started again for this new website and I've come along way since 2008 in terms of being able to develop a better website, however I was wondering if someone could show me a simple code using the PHPBB forums, that would change the word Login in my website to Logout in the same font and style using the PHPbb session. I've tried using the old code but it never changed the >Login< to >Logout< and the ./supportflight/login.php" url to "./supportflight/logout.php"

but that never worked.

Spoiler:
Code: Select all
<li><a href="./supportflight/login.php">Login<span class="subheader">Check in to your Concorde Flight</span></a></li>
</ul>
<!-- Navigation --></div>



The code I used was the following,

Spoiler:
Code: Select all
<?php
if($user->data['is_registered'])
//if($user->data['session_logged_in'])
     //user is logged in
{
     print $user->data['username'];
     echo' <a title="Leaving so soon?" href="' . append_sid("http://www.letstakeoff.com/en_gb/main/active/acsv2.php", 'mode=logout', true, $user->session_id). '">Log out</a>';
}
else
     //user is not logged in
{
     echo'<a title="Log In" href="./login.php">Log In</a>   
                  <a title="Register" href="./register.php"> Register</a>';
}
?>


Cheers
Robbie Garrett
Cadet I
Cadet I
 
Posts: 15
Joined: 28 Aug 2008, 05:44
Gender: Male
phpBB Knowledge: 4

Re: PHPBB3 Website Intergrating systems.

Postby Robbie Garrett » 14 Jun 2012, 10:55

Well got the page to work without errors or the bit I said above mucking up.

However if logged in the forum, it doesn't show logged in, and does not show logged out at all. Am I missing something??

This is what gets everything going.

Spoiler:
Code: Select all
<?php
define('IN_PHPBB', true);
define('IN_WEBSITE', true); 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../forums/';;
$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');

?>



Login/Logout code.

Spoiler:
Code: Select all
<li><?php
if($user->data['is_registered'])
//if($user->data['session_logged_in'])
     //user is logged in
{
     print $user->data['username'];
     echo' <a title="Leaving so soon?" href="' . append_sid("./logout.php", 'mode=logout', true, $user->session_id). '">Log out';
}
else
     //user is not logged in
{
     echo'<a title="Log In" href="./login.php">Log In';
}
?><span class="subheader">Concorde Flight Check in</span></a></li>
Robbie Garrett
Cadet I
Cadet I
 
Posts: 15
Joined: 28 Aug 2008, 05:44
Gender: Male
phpBB Knowledge: 4

Re: PHPBB3 Website Intergrating systems.

Postby Robbie Garrett » 15 Jun 2012, 10:43

After 6 straight hours of looking at the code, I have now been stuck doing the following for the last 6 hours.

A few years ago, I was given this code... but cannot find it for the love of life and who provided it.

Without it the form shows, but obviously doesn't work. With the following php code it doesn't display any content after it, at all.

I have the session initiation working perfect now,

Code: Select all
<?php
define('IN_PHPBB', true);
define('IN_WEBSITE', true); 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../../forums/';
$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');

?>


but no luck on this string.

Code: Select all
<?php

if($user->data['is_registered'])
{
        meta_refresh(0, 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, 8),
         ));

         // 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'   => "http://www.letstakeoff.com/en_gb/main/active/activate.$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_ACTIVATE'      => "./activate.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
                     );

                     $messenger->send($row['user_notify_type']);
                  }
                  $db->sql_freeresult($result);
               }
            }

                 
            $url = redirect('./../testphp/welcome.php', true);
            $time = 0;    //Seconds to wait before redirect

            echo '<meta http-equiv="refresh" content="' . $time . ';url=' . str_replace('&', '&amp;', $url) . '" />';
   
         }
      }

      $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 = '&amp;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, 8));
            $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&amp;id=' . $confirm_id . '&amp;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 />&bull;', $error) : '';
echo '<p>'.$error_display.'</p>';
}
?>



Clearly something is going wrong??
Robbie Garrett
Cadet I
Cadet I
 
Posts: 15
Joined: 28 Aug 2008, 05:44
Gender: Male
phpBB Knowledge: 4

Re: PHPBB3 Website Intergrating systems.

Postby topdown » 15 Jun 2012, 22:35

What is it that you are trying to do?

And how deep is that first file in the sites directories? ./../../forums/ ??

I see echo's for a meta refresh, but no other output or template setup/calls
So it makes it even more confusing as to what you want to accomplish with this.
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3021
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9

Re: PHPBB3 Website Intergrating systems.

Postby Robbie Garrett » 16 Jun 2012, 16:18

topdown wrote:What is it that you are trying to do?

And how deep is that first file in the sites directories? ./../../forums/ ??

I see echo's for a meta refresh, but no other output or template setup/calls
So it makes it even more confusing as to what you want to accomplish with this.


Hello Top Down,

Thank you very much for replying.

That is correct, the section of my website is http://www.concordeflight.org.uk/en/supportflight/ - I have it running off the forums at .org.uk/forums/ - this works perfectly fine and did so 4 years ago.

What I am looking to do is have the registration form inside my website template, so that when the user clicks register - they view my website but it uses the registration form and it's confirmation codes from the phpbb forums.

In 2008 when the form worked, on clicking my custom form. It would connect to ucp registration, send an email to your email provided, add your details to the database and on clicking the confirmation message, would go to my custom made confirmation email. This all worked fine. It would send emails (I did have to edit the email to my custom url, but other than that, it did everything for me) without actually having to click the forums and come away from the website.

Spoiler:
Code: Select all
<?php
define('IN_PHPBB', true);
define('IN_WEBSITE', true); 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../../forums/';
$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');

?>




This is the whole page and registration form, I have highlighted the key bits that SHOULD make the form work.

Spoiler:
Code: Select all
                     <!-- form -->
                     <h2>Registration Form - </h2>
                     <script type="text/javascript" src="js/form-validation.js"></script>
                     <form id="registration" action="./test.php" method="post"><?php

if($user->data['is_registered'])
{
        meta_refresh(0, 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, 8),
         ));

         // 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'   => "http://www.letstakeoff.com/en_gb/main/active/activate.$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_ACTIVATE'      => "./activate.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
                     );

                     $messenger->send($row['user_notify_type']);
                  }
                  $db->sql_freeresult($result);
               }
            }

                 
            $url = redirect('./../testphp/welcome.php', true);
            $time = 0;    //Seconds to wait before redirect

            echo '<meta http-equiv="refresh" content="' . $time . ';url=' . str_replace('&', '&amp;', $url) . '" />';
   
         }
      }

      $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 = '&amp;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, 8));
            $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&amp;id=' . $confirm_id . '&amp;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 />&bull;', $error) : '';
echo '<p>'.$error_display.'</p>';
}
?>
                        <fieldset>
                           <div>
                              <label>Your desired 'Username'</label>
                           <input id="username" type="text" size="25"  class="form-poshytip" maxlength="50" name="username" /></div>
                           <div>
                              <label>Email Address</label>
                              <input id="email" type="text" size="25" class="form-poshytip" maxlength="100" name="email" />
                           </div>
                                  <div>
                           <label>Password</label>
                             <input id="new_password" type="password" size="25" class="form-poshytip" maxlength="50" name="new_password" />
                          <p>
                                <label>Confirm Password</label>
                                <input id="password_confirm" type="password" size="25" class="form-poshytip" maxlength="50" name="password_confirm" />
                              </p>
                                  </div>
                                     <div>
<label for="confirm_image">Confirm Image: </label><?= $confirm_image ?><?= $s_hidden_fields ?>
</div> <div><input type="text" name="confirm_code" size="25" maxlength="8" /> <span class="note style21">Enter the code exactly as it appears. <br />All letters are case insensitive, there is no zero.</span></div>
                           <p><input type="button" value="Register" name="submit" id="submit" /></p>
                        </fieldset>
                     </form>
<!-- ENDS form -->[/color]
]



The form and the first code that goes at the top of the file works, only this bit is causing me problems.

Spoiler:
Code: Select all
<?php

if($user->data['is_registered'])
{
        meta_refresh(0, 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, 8),
         ));

         // 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'   => "http://www.letstakeoff.com/en_gb/main/active/activate.$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_ACTIVATE'      => "./activate.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
                     );

                     $messenger->send($row['user_notify_type']);
                  }
                  $db->sql_freeresult($result);
               }
            }

                 
            $url = redirect('./../testphp/welcome.php', true);
            $time = 0;    //Seconds to wait before redirect

            echo '<meta http-equiv="refresh" content="' . $time . ';url=' . str_replace('&', '&amp;', $url) . '" />';
   
         }
      }

      $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 = '&amp;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, 8));
            $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&amp;id=' . $confirm_id . '&amp;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 />&bull;', $error) : '';
echo '<p>'.$error_display.'</p>';
}
?>
Robbie Garrett
Cadet I
Cadet I
 
Posts: 15
Joined: 28 Aug 2008, 05:44
Gender: Male
phpBB Knowledge: 4

Previous

Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: No registered users and 10 guests