Topic: Can someone help me get my website form to login to forum?

Hi guys, I have spent well over a week on this one part, which is getting my website to log a user into the forum. I've read many articles and tried countless source code examples. I run into a lot of confusions, since it appears that the code has changed over the years so the old examples may no longer work?

Here's some of my confusions:
Some write "include", some write "require"
Some include "functions.php", some include "common.php". still not sure which ones I need.
I am using this:

require FORUM_ROOT.'include/common.php';

Some write "FORUM_ROOT", some write "PUN_ROOT"
I am using this:

if(!defined('FORUM_ROOT')) define('FORUM_ROOT', '/home/sites/example.com/public_html/forums/');
//in my source I have the correct domain instead of example.com

// and these too:
if(!defined('FORUM_TURN_OFF_MAINT')) define('FORUM_TURN_OFF_MAINT', 1);
if(!defined('FORUM_QUIET_VISIT')) define('FORUM_QUIET_VISIT', 1);

I also put these in, not sure if thats right:

$forum_page['redirect_url'] = "/index.php";
$forum_page['form_action'] = forum_link($forum_url['login']);
$forum_page['hidden_fields'] = array(
  'form_sent'=> '<input type="hidden" name="form_sent" value="1" />',
  'redirect_url' => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
  'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);

lastly the form:

<form method="post" action="<?php echo $forum_page['form_action'] ?>">
    <?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
 
    Username:
    <input type="text" id="fld1" name="req_username" value="" />
    <br />
 
    Password:
    <input type="password" id="fld2" name="req_password" value="" />
    <br />
 
    <input type="checkbox" id="fld3" name="save_pass" value="1" />
    <label for="fld3">Remember me</label>
    <br />
 
    <input type="submit" name="login" value="Login" />
</form>

I feel like its almost working, any advice would be massively appreciated.

2 (edited by PanBB.Ru 2016-02-03 08:47)

Re: Can someone help me get my website form to login to forum?

It is code from extensions Widgets For PunBB:

        <div class="main-content">
<?php
global $forum_user, $forum_url, $lang_common;
// If user is logged display some informations about it
if (!$forum_user['is_guest']) {
?>
            Привет, <strong><?php echo forum_htmlencode($forum_user['username']) ?></strong><br />
            <a href="<?php echo forum_link($forum_url['logout'], array($forum_user['id'], generate_form_token('logout'.$forum_user['id']))) ?>">Выйти</a>
            

<?php
} else {

    require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';
    $form_action = forum_link($forum_url['login']);
?>

            <a href="javascript://" rel="nofollow" onclick="location.href = '<?php echo forum_link($forum_url['register']) ?>';"><?php echo $lang_common['Register'] ?></a>
            <br />
            <form method="post" action="<?php echo $form_action ?>">
                <div class="hidden">
                    <input type="hidden" name="form_sent" value="1" />
                    <input type="hidden" name="redirect_url" value="<?php echo get_current_url() ?>" />
                    <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($form_action) ?>" />
                </div>
                <div class="panel-input">
                    <br />
                    <input type="text" name="req_username" size="13" placeholder="<?php echo $lang_login['Username'] ?>" />
                </div>
                <div class="panel-input">
                    <br />
                    <input type="password" name="req_password" size="13" placeholder="<?php echo $lang_login['Password'] ?>" />
                </div>
                <div>
                    <label for="fld-remember-me"><span class="fld-label"><?php echo $lang_login['Remember me'] ?></span>&nbsp;<input type="checkbox" id="fld-remember-me" name="save_pass" value="1" /></label>
                </div>
                <div>
                    <span class="submit"><input type="submit" name="login" value="Войти" /></span>
                </div>
            </form>
<?php

}
?>
        </div>

Re: Can someone help me get my website form to login to forum?

thanks for your source example, may I ask, which include\require is needed for this: $forum_user['is_guest']  ??

Re: Can someone help me get my website form to login to forum?

Update: I found a working example, but when I tried to use it in the same situations I've been trying, it didnt work. So I think it is related to using .tpl files (templates). So I am going to try and display my form before the template is applied. That should solve it, thanks again.

5 (edited by PanBB.Ru 2016-02-04 10:05)

Re: Can someone help me get my website form to login to forum?

1/ create a new file with name login.php in /include/user/login.php.
2/ added it is code. See up.
3/ include file login.php in main.tpl    /include/template/main.tpl.
Open main.tpl and paste

    <div id="brd-visit" class="gen-content">
        <!-- forum_welcome -->
        <!-- forum_include "login.php" -->
        <!-- forum_visit -->

all   )))

See more   Widgets For PunBB