1 (edited by N3twork2 2009-05-19 11:05)

Topic: Create a external form for login

Hello

I have Punbb 1.3.3

I work in ma website for integrate PUNBB

I should have a form in my website for member can login, or register.

Can you hep me ?

<form  method="post" action="http://www.website.com/"> REDIRECTION IN INDEX OF WEBSITE (No index of forum)

                <input type="hidden" name="form_sent" value="1" />
                <input type="hidden" name="redirect_url" value="http://www.website.com" />
                <input type="hidden" name="csrf_token" value=" HOW GENERATE A GOOD csrf Token ???" />


<label for="fld1"><span>Utilisateur <em>(Obligatoire)</em></span></label><br />
<span class="fld-input"><input type="text" id="fld1" name="req_username" value="" size="35" maxlength="25" /></span>

<label for="fld2"><span>Mot de passe <em>(Obligatoire)</em></span></label><br />
<span class="fld-input"><input type="password" id="fld2" name="req_password" value="" size="35" /></span>

<span class="fld-input"><input type="checkbox" id="fld3" name="save_pass" value="1" /></span>
<label for="fld3"><span>Se souvenir de moi</span> Connexion automatique à chacune de mes visites.</label>


<span class="submit"><input type="submit" name="login" value="Connexion" /></span>

        </form>

Re: Create a external form for login

This is how the CSRF token is generated in login.php (line 360):

$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_user['prev_url']).'" />',
    'csrf_token'    => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);

You have to include common.php to use the generate_form_token function:

<?php
 
// Add these lines in the very top of your code
define('FORUM_ROOT', 'forum/');
require FORUM_ROOT.'include/common.php';
 
?>

(See the wiki integration page for details.)

Re: Create a external form for login

i wanted the same thing. and i posted this in my sidebar here is the error i got:

Fatal error: Call to a member function escape() on a non-object in /home/supermag/public_html/community/include/functions.php on line 1350
<?php
 
// Add these lines in the very top of your code
define('FORUM_ROOT', 'community/');
require FORUM_ROOT.'include/common.php';
 
?>
<form  method="post" action="/"> REDIRECTION IN INDEX OF WEBSITE (No index of forum)
$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_user['prev_url']).'" />',
    'csrf_token'    => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);
<label for="fld1"><span>Username <em>(Required)</em></span></label><br />
<span class="fld-input"><input type="text" id="fld1" name="req_username" value="" size="35" maxlength="25" /></span>
<label for="fld2"><span>Password <em>(Required)</em></span></label><br />
<span class="fld-input"><input type="password" id="fld2" name="req_password" value="" size="35" /></span>
<span class="fld-input"><input type="checkbox" id="fld3" name="save_pass" value="1" /></span>
<label for="fld3"><span>Remember me</span> Remember me Log me in automatically each time I visit.</label>

<span class="submit"><input type="submit" name="login" value="Login" /></span>
        </form>

My forum place is: http://sports2all.com/community/

So can some one correct me what i did wrong. Thanks

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

I've fixed your code and added it to the wiki: http://punbb.informer.com/wiki/punbb13/ … _the_forum.

Re: Create a external form for login

hey Parpalak, i implemented ur code and got this error:

Fatal error: Call to a member function escape() on a non-object in /home/supermag/public_html/community/include/functions.php on line 1350
MyFootballCafe.com  is Now Online!

Re: Create a external form for login

It happens because you put the code inside a function. There are two solutions, the first (to place require FORUM_ROOT.'include/common.php'; in the global scope) is better.

<?php

// Define the path to the forum root
define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';

function my_login_form() {

    global $forum_url;

    // Where will we go after login?
    $forum_page['redirect_url'] = 'http://punbb/';

    $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']).'" />'
    );

?>
<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">Log me in automatically each time I visit.</label>
    <br />

    <input type="submit" name="login" value="Login" />
</form>

<?

}

my_login_form();
<?php

function my_login_form() {

    global $forum_url, $forum_db, $forum_user, $forum_config, $base_url;

    // Define the path to the forum root
    define('FORUM_ROOT', './');
    require FORUM_ROOT.'include/common.php';

    // Where will we go after login?
    $forum_page['redirect_url'] = 'http://punbb/';

    $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']).'" />'
    );

?>
<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">Log me in automatically each time I visit.</label>
    <br />

    <input type="submit" name="login" value="Login" />
</form>

<?

}

my_login_form();

Re: Create a external form for login

ok i used the first code and i got this error:

Fatal error: Call to a member function escape() on a non-object in /home/supermag/public_html/community/include/functions.php on line 1350

-------------------------------


The second code is weared.

at the widget place it gives this error:

Fatal error: require() [function.require]: Failed opening required './community/include/common.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php(37) : eval()'d code on line 9

but when u see the home page, there is a login block.

when i sign in. it iframes the whole forum page (which also create a BIG mess and shows this note:

You appear to have logged in successfully, however a cookie has not been set. Please check your settings and if applicable, enable cookies for this website.

after i refresh my page, it appears i am not logged in.

-----------------------------------

i used two plugins of wordpress which allows PHP in widgets. Executable PHP widget    and Samsarin PHP Widget. Both plugins give the same result.

Is there anyway i can fix these stuff.

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

The code above is just an example.

However, one can copy it into a php file and obtain a correctly functioning login form.

Your question is related sooner to Wordpress than PunBB.

Re: Create a external form for login

ok, so i need to copy the code to a file.

but i don't know how to load that file. so is there any example. oh how can i do that.

and where should i place the file.

In the forums directory or the main site.

Thanks

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

mmm how do u load php file into HTML. (what function is used)

MyFootballCafe.com  is Now Online!

11

Re: Create a external form for login

Require or include.

http://uk.php.net/manual/en/function.require.php
http://uk.php.net/manual/en/function.include.php

Re: Create a external form for login

damn, tried both functions but ended up getting this error

Warning: require() [function.require]: URL file-access is disabled in the server configuration in /home/supermag/public_html/sitetools/pages/login.php on line 5

MyFootballCafe.com  is Now Online!

13

Re: Create a external form for login

SuperMAG wrote:

damn, tried both functions but ended up getting this error

Warning: require() [function.require]: URL file-access is disabled in the server configuration in /home/supermag/public_html/sitetools/pages/login.php on line 5

What file have you tried to include?

Re: Create a external form for login

http://sports2all.com/sitetools/pages/login.php

<?php

// Define the path to the forum root
define('FORUM_ROOT', '../community/');
require FORUM_ROOT.'include/common.php';

function my_login_form() {

    global $forum_url;

    // Where will we go after login?
    $forum_page['redirect_url'] = 'http://sports2all.com/community/';

    $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']).'" />'
    );

?>
<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">Log me in automatically each time I visit.</label>
    <br />

    <input type="submit" name="login" value="Login" />
</form>

<?

}

my_login_form();

And it code place:

<?php

include '../sitetools/pages/login.php';

?>

is there any thing wrong with what i did?

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

Seems like FORUM_ROOT is defined incorrect.

Re: Create a external form for login

i have my forum http://sports2all.com/community/

so what should i change to.

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

If the file is http://sports2all.com/sitetools/pages/login.php and the forum is http://sports2all.com/community/ then you should write

define('FORUM_ROOT', '../../community/');

Doesn't require any PHP knowledge, does it?

Re: Create a external form for login

lol i though double .. means the first directory

but i still get this error:

Warning: include(../../sitetools/pages/login.php) [function.include]: failed to open stream: No such file or directory in /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php(37) : eval()'d code on line 2

Ok

If the file is here: http://sports2all.com/sitetools/pages/login.php
Forums are here: http://sports2all.com/community/
And the Wordpress plugin that executes php in widgets is here: http://sports2all.com//wp-content/plugi … xecphp.php

how should i do the include code, i tried both ../sitetools/pages/login.php and ../../sitetools/pages/login.php but its still showing the above error.

mmm hmm lol

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

SuperMAG! You had written that the error is in your /home/supermag/public_html/sitetools/pages/login.php file:

SuperMAG wrote:

Warning: require() [function.require]: URL file-access is disabled in the server configuration in /home/supermag/public_html/sitetools/pages/login.php on line 5

I had told you to change the define('FORUM_ROOT', ...) in that file (/home/supermag/public_html/sitetools/pages/login.php) on line 4 because there is the error on line 5.

But you have obviously changed another file, /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php. And now the include command in your /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php file can't find the /home/supermag/public_html/sitetools/pages/login.php file.

Gosh!

Now, rollback the changes in /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php and modify the define('FORUM_ROOT', ...) on line 4 in /home/supermag/public_html/sitetools/pages/login.php.

Re: Create a external form for login

BTW, there can be an issue with relative paths when one tries to include a file A into a file B, and then the file B into a file C (just like you do). It's better to write something like this:

define('FORUM_ROOT', $_SERVER['DOCUMENT_ROOT'].'/community/');

Re: Create a external form for login

what u r talking about, here is my Current Login.php

<?php

// Define the path to the forum root
define('FORUM_ROOT', '../../community/');
require FORUM_ROOT.'include/common.php';

function my_login_form() {

    global $forum_url;

    // Where will we go after login?
    $forum_page['redirect_url'] = 'http://sports2all.com/community/';

    $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']).'" />'
    );

?>
<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">Log me in automatically each time I visit.</label>
    <br />

    <input type="submit" name="login" value="Login" />
</form>

<?

}

my_login_form();

even after i modified the

define('FORUM_ROOT', $_SERVER['DOCUMENT_ROOT'].'/community/');

but still get this error:

Warning: include(../../sitetools/pages/login.php) [function.include]: failed to open stream: No such file or directory in /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php(37) : eval()'d code on line 2


But i still dont know if this is correct Include:

<?php
include '../sitetools/pages/login.php';
?>

And i didnt messed with the plugin file. just edited that login and a widget.
http://sports2all.com//wp-content/plugi … xecphp.php

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

SuperMAG wrote:

But i still dont know if this is correct Include

Actually depends on where you place it.

It's quite a good code, and it works if you have really got the error described here: http://punbb.informer.com/forums/post/128228/#p128228

But it's better to write

<?php
include $_SERVER['DOCUMENT_ROOT'].'/sitetools/pages/login.php';
?>

Re: Create a external form for login

SuperMAG wrote:

Warning: include(../../sitetools/pages/login.php) [function.include]: failed to open stream: No such file or directory in /home/supermag/public_html/wp-content/plugins/php-code-widget/execphp.php(37) : eval()'d code on line 2

SuperMAG wrote:

And i didnt messed with the plugin file. just edited that login and a widget.

Ok, I've got it.

Re: Create a external form for login

LoL i got 2 new kinds of error

This one in the Widget place:

Fatal error: Cannot redeclare validate_username() (previously declared in /home/supermag/public_html/wp-includes/registration.php:49) in /home/supermag/public_html/community/include/functions.php on line 864

And This one at the pages:

Fatal error: Call to a member function escape() on a non-object in /home/supermag/public_html/community/include/functions.php on line 1350

LoL again.

MyFootballCafe.com  is Now Online!

Re: Create a external form for login

This means that PunBB and Wordpress both have functions validate_username(). So integration is not as easy. Maybe it's worth to copy the generate_form_token() function from PunBB core into a separate file. I'll return to this question after some days.