Another integration question
Posted by parduezy
Re: Another integration question May 17, 2010 08:12PM |
Registered: 15 years ago Posts: 17 |
Quote
Maurice Makaay
The external authentication module uses a different variable name for storing the sessions. Also, at the end you won't have to return it. Just set the active sessions in the variable as provided by external authentication. It was something like $phorum_sessions I think, but check the examples as included in the bundle to check if this is correct.
I dont see $phorum_sessions, I see
$session_data[PHORUM_SESSION_LONG_TERM] = $user_id;
$session_data[PHORUM_SESSION_SHORT_TERM] = $user_id;
Is this it?
May 17, 2010 08:19PM |
Admin Registered: 20 years ago Posts: 8,532 |
Re: Another integration question May 17, 2010 08:32PM |
Registered: 15 years ago Posts: 17 |
I've got no clue what's wrong with it, I've tried just about everything.
that's the updated code, but it's like it just doesn't recognize the session. Any ideas? It's beginning to get frustrating to figure out.
Language: PHPif (!session_id()) session_start(); // If the user is logged into the main session, then tell Phorum // to use the user_id from the session. if (!empty($_SESSION[';user_id';])) { $session_data[PHORUM_SESSION_LONG_TERM] = $user_id; $session_data[PHORUM_SESSION_SHORT_TERM] = $user_id; }
that's the updated code, but it's like it just doesn't recognize the session. Any ideas? It's beginning to get frustrating to figure out.
May 17, 2010 08:50PM |
Admin Registered: 20 years ago Posts: 8,532 |
Hard to tell without knowing your setup. E.g. is $_SESSION['user_id'] actually the user id as setup by your main application or is your main app handling sessions differently? And did you also create a Phorum user for the provided user id, prior to trying to enforce a session for that user through this hook construction? If you have no matching Phorum user, then setting the user id through the user_session_restore hook will never work.
Something tells me that all of the above might be true. So far, you seem to be copying and pasting pieces of code, trying to get it to work. Coding rarely works like that. Maybe I'm wrong of course.
The clear issue in the code that you pasted is that you check $_SESSION['user_id'] and you set $user_id. That $user_id variable is never initialized.
The code should therefore at least read:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Something tells me that all of the above might be true. So far, you seem to be copying and pasting pieces of code, trying to get it to work. Coding rarely works like that. Maybe I'm wrong of course.
The clear issue in the code that you pasted is that you check $_SESSION['user_id'] and you set $user_id. That $user_id variable is never initialized.
The code should therefore at least read:
if (!empty($_SESSION['user_id'])) { $session_data[PHORUM_SESSION_LONG_TERM] = $_SESSION['user_id']; $session_data[PHORUM_SESSION_SHORT_TERM] = $_SESSION['user_id']; }
Maurice Makaay
Phorum Development Team



Re: Another integration question May 17, 2010 09:00PM |
Registered: 15 years ago Posts: 17 |
Quote
Maurice Makaay
Hard to tell without knowing your setup. E.g. is $_SESSION['user_id'] actually the user id as setup by your main application or is your main app handling sessions differently? And did you also create a Phorum user for the provided user id, prior to trying to enforce a session for that user through this hook construction? If you have no matching Phorum user, then setting the user id through the user_session_restore hook will never work.
Something tells me that all of the above might be true. So far, you seem to be copying and pasting pieces of code, trying to get it to work. Coding rarely works like that. Maybe I'm wrong of course.
The clear issue in the code that you pasted is that you check $_SESSION['user_id'] and you set $user_id. That $user_id variable is never initialized.
The code should therefore at least read:
if (!empty($_SESSION['user_id'])) { $session_data[PHORUM_SESSION_LONG_TERM] = $_SESSION['user_id']; $session_data[PHORUM_SESSION_SHORT_TERM] = $_SESSION['user_id']; }
YES! This was it^.. Thanks Maurice for all your help!
May 17, 2010 09:05PM |
Admin Registered: 20 years ago Posts: 8,532 |
Great, have fun with it!
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Re: Another integration question May 17, 2010 09:56PM |
Registered: 15 years ago Posts: 17 |
Hey Maurice, is the approach the same when it comes to logging out? I want to logout from my main site, when I do that now it leaves the user logged in to the forum.. I notice that there are a couple cookies
name - phorum_session_v5
phorum_session_v5 - 2%3Af95a9ee79834793f373259cfacfcce38
host - mywebsite.com
path - /forum
name - PHPSESSID
content - 1e78992a237453473bacc1a902ee232b
host - mywebsite.com
path - /
My logout page:
name - phorum_session_v5
phorum_session_v5 - 2%3Af95a9ee79834793f373259cfacfcce38
host - mywebsite.com
path - /forum
name - PHPSESSID
content - 1e78992a237453473bacc1a902ee232b
host - mywebsite.com
path - /
My logout page:
Language: PHP<?php session_start(); /************ Delete the sessions ************/ unset($_SESSION[';user_id';]); unset($_SESSION[';user_name';]); /************ Delete the cookies ************/ setcookie("user_id", ';';, time()-60*60*24*60, "/"); setcookie("user_name", ';';, time()-60*60*24*60, "/"); /************ redirect to home page ************/ header(';Location: http://'; . $_SERVER[';HTTP_HOST';] . $_SERVER[';REQUEST_URL';].';/site/';); ?>
May 17, 2010 10:04PM |
Admin Registered: 20 years ago Posts: 8,532 |
From the user_session_restore hook you can tell Phorum explicitly that no session is available. From the developer documentation for this hook:
Therefore, you will need an else block in your code to logout the user:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Quote
Phorum developer documentation
The array that is passed to this hook, contains a key for each of the Phorum session types:
* PHORUM_SESSION_LONG_TERM
* PHORUM_SESSION_SHORT_TERM
* PHORUM_SESSION_ADMIN
What the module has to do, is fill the values for each of these keys with the user_id of the Phorum user for which the session that the key represents should be considered active. Other options are FALSE to indicate that no session is active and NULL to tell Phorum to handle session restore on its own.
Therefore, you will need an else block in your code to logout the user:
if (!empty($_SESSION['user_id'])) { $session_data[PHORUM_SESSION_LONG_TERM] = $_SESSION['user_id']; $session_data[PHORUM_SESSION_SHORT_TERM] = $_SESSION['user_id']; } else { $session_data[PHORUM_SESSION_LONG_TERM] = FALSE; $session_data[PHORUM_SESSION_SHORT_TERM] = FALSE; }
Maurice Makaay
Phorum Development Team



Re: Another integration question May 18, 2010 05:02PM |
Registered: 15 years ago Posts: 17 |
Hey Maurice, i'm having a weird problems. I have no issue login in, posting, replying, however my test users are having problems. I had 2 friends create accounts on my main page where I insert in 2 different tables, my user table and the phorum_users table. My code for the phorum_users insert is
The users show up in both databases fine, I have no issue with my account like I said posting or replying but 2 of my users, different states/different houses say when they try and reply it says "Sorry, only registered users may post in this forum."
Why would I have no issue but they would?
Thanks
Language: PHPmysql_query("INSERT into phorum_users(`username`,`display_name`,`password`, `email`, `active`, `admin`, `date_added`) VALUES (';$user_name';,';$user_name';, ';$md5pass';, ';$usr_email';, ';1';, ';0';,';$time';)") or die(mysql_error());
The users show up in both databases fine, I have no issue with my account like I said posting or replying but 2 of my users, different states/different houses say when they try and reply it says "Sorry, only registered users may post in this forum."
Why would I have no issue but they would?
Thanks
May 18, 2010 05:10PM |
Admin Registered: 20 years ago Posts: 8,532 |
Maybe forum permissions that don't allow regular users access to the forum(s)?
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Sorry, only registered users may post in this forum.