1

Topic: integrating your own site login with punbb - my tip

i think i'll post here because i see many of you have problems with logging.. i haven't found any clear answer about integrating log-on, so did it my way a few minutes ago.. it's a way to intergate a complete separate log-on..

f.ex. my login class sets some session data, no cookies... punbb sets cookies, no session.. completely different. and that's how you do it:
wherever your logins are, must be the same, and the passwords to, but you know that i hope, (f.ex. i have other table with logins and passwords and other user data, but the username and md5(pass) must be the same... uploaded them to punbb tables)

4 situations you must predict and solve the problem


1. user is logging from your site

in your login class, function, script, whatever, put after your operations this:

include("./forum/config.php");
include("./forum/include/functions.php");
setcookie($cookie_name, serialize(array($your_sent_login, pun_hash($your_sent_pass))), $expire, $cookie_path, $cookie_domain, $cookie_secure);

of course the forum directory path may be other in your case.
it sets the coookie for the forum.. as you can see, now when you logon on your site, the cookie is set and you're logged on the forum..


2. if the user logs on by forum

on the top of /includes/common.php put session_start();

in /login.php, find the lines below and put code before:

/ * your site login code in here, session data saving, maybe database update, etc... of course put it in a working way, don't blame the forum :) if it's included ok - it must work */
setcookie($cookie_name, serialize(array($db_username, $form_password_hash)), $expire, $cookie_path, $cookie_domain, $cookie_secure);
redirect($_POST['redirect_url'], $lang_login['Login redirect']);


3. user loggs out from your site

in your private  logging out code put this:

include("./forum/config.php");
include("./forum/include/functions.php");
setcookie($cookie_name, serialize(array('Guest', 'Guest')), time() + 31536000, $cookie_path, $cookie_domain, $cookie_secure);


4. user logging out from the forum

find these lines and put your logging out code

setcookie($cookie_name, serialize(array('Guest', 'Guest')), time() + 31536000, $cookie_path, $cookie_domain, $cookie_secure);
/* here your private logging out code */
redirect('index.php', $lang_login['Logout redirect'])



that's all folks, somebody has any other (maybe easier) ways?

Re: integrating your own site login with punbb - my tip

Oh thank you! That's exactly what I needed right now in this moment! smile

Re: integrating your own site login with punbb - my tip

Anyone have success with this one? i try, but nothing happen :-( .. Please help... maybe this code is for old version?

Fain xoxo

Re: integrating your own site login with punbb - my tip

I have all the "integration" in a class... the methods:

function check_login()
    {
    IF($this->pun_user['group_id'] == 3)    return false;
    IF($this->pun_user['username'] == 'Guest')    return false;
    IF($this->pun_user['password'] == 'Guest')    return false;
    IF($this->pun_user['id'] == 1)    return false;
    return true;
    }
function logout()
    {
    punapi::query('DELETE FROM '.$this->db_prefix.'online WHERE user_id='.$this->pun_user['id']);
    pun_setcookie(1, random_pass(8), time() + 31536000);
    }
function login_form()
    {
    ob_start();
    echo '<center><form id="login" method="post" action="'.PUN_ROOT.'login.php?action=in" onsubmit="return process_form(this)">
    <input type="hidden" name="form_sent" value="1" />
    <input type="hidden" name="redirect_url" value="'.$_SERVER['SCRIPT_NAME'].'" />
    <B>'.$this->lang[5].'</B><BR />
    <input type="text" name="req_username" size="15" maxlength="25" /><BR /><BR />
    <B>'.$this->lang[6].'</B><BR />
    <input type="password" name="req_password" size="15" maxlength="16" /><BR /><BR />
    <input type="submit" name="login" value="Login" />
    </form></center>';
    $module = ob_get_contents();
    ob_end_clean();
    return $module;
    }
function login_block()
    {
    ob_start();
    IF (punapi::check_login() == true)
        {
        echo $this->lang[11].'.<center><B><A href="index.php?mod=user&act=logout">'.$this->lang[9].'</a></b></center>';
        echo '<BR><center>[<a href="index.php?mod=user&act=editp">'.$this->lang[13].'</a>]</center>';
        echo '<center>[<a href="index.php?mod=user&act=mail"><B><U>'.$this->lang[19].'</U></B></a>]</center>';
        }
    elseIF (punapi::check_login() == false and isset($_POST['login']))
        {
        echo $this->lang[10];
        echo '<META HTTP-EQUIV="Refresh" CONTENT="2; URL=index.php">';
        }
    elseIF (punapi::check_login() == false)
        {
        echo punapi::login_form();
        echo '<BR><center>[<a href="forum/register.php">'.$this->lang[12].'</a>]</center>';
        echo '<center>[<a href="index.php?mod=user&act=mail"><B><U>'.$this->lang[19].'</U></B></a>]</center>';
        }
    $module = ob_get_contents();
    ob_end_clean();
    return $module;
    }

The "login_block" is for login/logout/register thing (using punBB system)
And on /index.php before the classes are called  I have:

define('PUN_ROOT', 'forum/');
include_once PUN_ROOT.'include/common.php';
My site [PHP, Python, Linux]