Firefox PHP

How to check login status on phorum based site?

Posted by Terradon 
How to check login status on phorum based site?
December 20, 2012 06:13PM
Hi,
i want to use phorum-functions for a portal-site.
I know i have to include common.php in my header-file, so all main phorum functions are always available.
I will use the original login page (xxxxxxxx.nl/forum/login.php).

But, after including common.php in site-pages, how do i check if an user is logged in for phorum (and by this, logged in for the whole website?)

Something like:
Language: PHP
if(loggedin) //do this else //do something else
Re: How to check login status on phorum based site?
December 21, 2012 08:13AM
If you are using cookies on your site, there will be a variable phorum_session_v5 that is set. If this matches the sessid_lt field in the phorum users table, the user is logged in.
This assumes you aren't using a short session logout. The cookie variable is set up as userid, %3A, and then the sessid_lt field. You will have to do a little more processing if you pass session info without using a cookie.

There is an api call "phorum_api_user_get_active_user" which will return the logged in user or null (if not logged in in 5.2.16+) this requires loading common.

If all you are concerned with is seeing if someone is logged in, there is/was a Quick Authentication Module (I believe it is just some php code you include in the other pages to check log in status). It doesn't require all the heavy lifting of incorporating the phorum common files.

[www.phorum.org]



Edited 1 time(s). Last edit at 12/21/2012 12:13PM by DavidVonB.
Re: How to check login status on phorum based site?
December 21, 2012 03:30PM
David,
the quick authentication script works fine, but i want to play around with common.php too, just giving it a try, to see if i have any advantages above the quick method.
On another website i have integrated an external authentication system, which works fine too, but in my opinion, saving the same (user) data twice, goes against all efficiency rules and gives possibilities for a break in the integrity of my (user) data.

On the other website i have integrated phorum afterwards, but now i am developing a completely new website. So now i have the chance to find out how to save user data effeciently, meaning by phorum only:)

I started with the quick authentication first and it works perfectly, but i am just wondering, if I include common.php in my header-file, if i can have more profit of phorum functions.

Of course I can create some session vars, after users have logged in and write some specific functions to handle al kind of things inside the phorum tables. (As I do with the other website). But again, writing own ph_xxxxxx() functions, are a source of terror on the data-integrity of my phorum tables. Doing something wrong, can lead to horrible problems, so i have experienced.

If I understand it right, it is just a matter of:

Language: PHP
$logged_in_user = phorum_api_user_get_active_user();

Is this correct?
Re: How to check login status on phorum based site?
December 21, 2012 03:54PM
Got it!
But needed to change directory, before including common.php, else i got errors about not finding includes/requires from common.php, because of an broken path.

Language: PHP
$current_dir = getcwd(); // current directory chdir($_SERVER["DOCUMENT_ROOT"].';/forum';); // serverpath to my phorum installation require(';common.php';); chdir($current_dir); // back to original directory   $aUser = phorum_api_user_get_active_user(); print_r($aUser); // display array of userdata, so you know what you can acces.

For production websites, you need to check if $aUser is an array with is_array($aUser), if not => visitor is not logged in:)
Sorry, only registered users may post in this forum.

Click here to login