Forum Moderators: coopster

Message Too Old, No Replies

PHPBB3 - integrating login with the rest of the site

         

Readie

6:22 am on Feb 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, one of the things I really want to do on my site is integrate the forums with the rest of the site a bit. So, there are several things that need doing for this:

1. The login function.
A login would be very simple if I was less fussy - I'm going to be having a (log in form / account options) at the top of every page on my site - I could have it post to the existing login screen, but that would then send me to the forums index, which I do not want.

I've searched for AGES on google, and through the actual code but have been unable to find the answer: so does anyone know what the login function(s)'s name is, and within what file it is located for PHPBB3?

2. Sessions / cookies
To actually properly intergrate it, I need to know the names (and values) of the sessions / cookies set when logging in, this includes the "keep me logged in" cookie.

3. Database changes
I should imagine there are several database changes/updates that occur during the login, in the case of these not being included within the existing login function (although I shouldn't see why they are not) I would like to know what they are.



I would be extremley grateful if anyone who has done this before could answer the above questions for me, and if they could tell me if there is anything else I need to know for doing this.

jatar_k

2:04 pm on Feb 25, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



1. not sure, i've done this same thing long ago, I just loaded the login page and followed the trail from there, form action, scripts, functions

2. dump the $_COOKIE array and see

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';

3. phpbb does, or used to anyway, use the db for session management but you should be able to use that same table by using the functions phpbb uses to update the db for every pageview on your other pages.

Readie

3:22 pm on Mar 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the reply jatar_k - sorry for resurrecting this old thread, and for not replying - but it took me a while to get around to doing this.

---- Session management ----

$_COOKIE['phpbb3_l2nvy_sid']
Is equal to the MySQL cell
sessions.session_id

sessions.session_user_id
Is equal to the MySQL cell
users.user_id

So, you would do this like so:

$this_sess = $_COOKIE['phpbb3_l2nvy_sid'];
$sql = 'SELECT users.user_id, users.username FROM users INNER JOIN sessions ON users.user_id=sessions.session_user_id WHERE sessions.session_id="' . $this_sess . '"';

---- Login ----

Quite simple for this one really

<form action="/forums/ucp.php?mode=login" method="post">
<input class="post" type="text" name="username" tabindex="1" />
<input class="post" type="password" name="password" tabindex="2" />
<input type="checkbox" name="autologin" tabindex="3" /><!-- Automatically sign in -->
<input type="checkbox" class="radio" name="viewonline" tabindex="4" /><!-- Hide login status -->
<input type="hidden" name="redirect" value="(RETURN LOCATION)" />
<input type="submit" name="login" value="Login" tabindex="5" />
</form>

Replacing "RETURN LOCATION" as appropriate

---- Logout ----

$this_sess = $_COOKIE['phpbb3_l2nvy_sid'];

...

echo '<a href="/forums/ucp.php?mode=logout&sid=' . $this_sess . '">Logout</a>'

Haven't worked out how to get it to sign out to the page of my choosing.
Haven't worked out how to get auto sign in to work on main site.

Will post again when/if I have

Readie

6:12 pm on Mar 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Selection SQL needs to also have
 AND sessions.session_user_id!="1"';

Messages found on phpbb.com lead me to believe it is impossible to change logout location without making large changes to the code.

Auto sign in appears to work with no additional input from me.

Readie

9:24 pm on Mar 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Back again :) auto login wasn't working in actuality.

session_keys.key_id
is an md5 hash of
$_COOKIE['phpbb3_l2nvy_k']

So that needs to have checks run on it too.