Firefox PHP

How can I integrate Phorum into an existing site with a single login?

Posted by PleaseHelp 
How can I integrate Phorum into an existing site with a single login?
July 01, 2011 08:34PM
Hello,

I just finished installing Phorum for the first time on my PHP/MySQL site. I must say, my first impression is quite good, so congrats on an excellent piece of software. I am a long-term vBulletin user/admin and when it came time to integrate a forum into one of my existing sites, vBulletin was simply too complicated. In fact, I am already loving the simplicity of Phorum as everything is a lot easier to do in comparison. When researching which forum software to use for the site in question, I compared options and Phorum seemed to have one of the most flexible Hook systems for integration with an existing site. Problem is, I've never used a Hook system and I've never integrated a forum into an existing site before. That's where this post comes in.

In short, what I wish to do is to integrate Phorum into my existing site such that when an existing or new user logins or registers for my site, they automatically gain access to Phorum without having to login again. As long as they are logged in to the main site, they should be able to post in the Phorum.

From what I've read so far, I will have to set the main Phorum user table as a duplicate of the existing main user table for this to work. However, I am not sure how to do that as I am unfortunately not an expert in either PHP or such integrations, but I do learn fast and know enough to get my hands dirty. So I am hoping someone here can be kind enough to give me a step-by-step guide on how to integrate Phorum as per the above.

For the sake of thoroughness, the current authentication on my site does a standard DB check for the username and (encrypted) password and, if it checks out, sets the custom session variable $_SESSION['Authentication']['LoggedIn'] to "true". As long as that session variable exists and is set to true, the user is considered logged in. I should probably add that due to the particulars of my site and userbase, the Session ID is passed around in the URL, so you can copy and paste a logged-in users' URL and be logged into their session.

I presume that one of the first things I will need to do is somehow duplicate my existing user table onto the main Phorum user table, but I am not sure how to do that.

So, where do I begin?

Thanks a lot, I greatly appreciate it!
Re: How can I integrate Phorum into an existing site with a single login?
July 02, 2011 12:51PM
Quote

I presume that one of the first things I will need to do is somehow duplicate my existing user table onto the main Phorum user table, but I am not sure how to do that.

Maybe yes, maybe no. If you have session variables that include a unique userID/Name and email, then you do not need to specially work on the Phorum users table (PMs would only work for people who have visited the forum).

You can use the mod at [www.phorum.org] to provide authentication and user table synchronization. You would have to modify the (from the mod file)
'user_id' => $_SESSION['userID'],
'username' => $_SESSION['username'],
'password' => '*NO PASSWORD SET*', // not needed for regular users
'email' => $_SESSION['userEmail'], // needed for e-mail notifications

in the function inherit_authentication_from_session($session_data)
Re: How can I integrate Phorum into an existing site with a single login?
July 04, 2011 06:42AM
Hi DavidVonB,

Thanks for the reply.

What you posted sounded too good to be true, until I tried it myself and it worked! I'm amazed that integrating Phorum with an existing user management system is as simple as installing a single Module that is less than 100 lines of code. Kudos to Terradon and Maurice Makaay for hacking that out. It worked like a charm and the user was created on-the-fly in the Phorum DB and automatically logged in. It doesn't get much simpler than that!

But alas, my work is not yet done. I have a few issues particular to my site which I would like to tackle one at a time with you guys in order to keep things manageable.

The first issue is related to how my site handles Sessions. As I mentioned in my original post, the Sessions get passed via URL, yet Phorum is not built that way. So whereas I can link from my main site to Phorum with the Session ID appended to the Phorum URL so that it can pull the Session Data and integrate the user, any links actually contained within Phorum do not append the Session ID so they work as if the user were logged-out since no Session Data is passed beyond the landing page.

So how can I get Phorum to automatically append the Session ID it receives from the main site to every link on the site so that the Session continues to get passed around?

Thanks again!



Edited 1 time(s). Last edit at 07/04/2011 06:43AM by PleaseHelp.
Re: How can I integrate Phorum into an existing site with a single login?
July 04, 2011 07:57AM
Quote

So how can I get Phorum to automatically append the Session ID it receives from the main site to every link on the site so that the Session continues to get passed around?

In the Phorum general Settings page from admin:
Cookie/Session Settings - section

Use Cookies
Phorum can track logged in users by using cookies or session information on URLs.

Use no cookies: The session information will always be included on the URL.

Allow cookies: The session information will be stored in cookies, if the user's browser supports it. Otherwise the information is included on the URL.

Require cookies: Session information is only stored in cookies. If the user's browser does not support cookies, the user will not be able to login.
Re: How can I integrate Phorum into an existing site with a single login?
July 04, 2011 09:00AM
Quote
DavidVonB
In the Phorum general Settings page from admin:
Cookie/Session Settings - section
Use no cookies: The session information will always be included on the URL.

Thanks, I was able to set the Cookie settings to use NO cookies.

However, I have encountered two issues.

One, the URL Session parameter used by Phorum is different from the one used by my main site.

Two, possibly due to the above, although now every link has a "phorum_session_v5" parameter when I visit the Phorum from my main site using my main site's Session parameter, when I click on any of them, it still views it as a logged-out user. To be clear, when I link from my main site in this way, the user is automatically logged into Phorum (and created if they do not exist in the Phorum database) as expected, but then any link that is clicked is viewed as a logged-out user even they all have the Phorum-specific Session parameter. The main site's Session parameter gets lost at this point, so something seems to be getting lost in translation.


Any idea how I can resolve the two issues above?

Thanks again!



Edited 1 time(s). Last edit at 07/04/2011 09:01AM by PleaseHelp.
Re: How can I integrate Phorum into an existing site with a single login?
July 05, 2011 10:13AM
First a disclaimer, I run phorum with cookies and don't use URL authentication.

I think what may be tripping you up is
The critical bit of code is at the end of the mod
$session_data[PHORUM_SESSION_LONG_TERM] = $user_id;

I think that you need to include your standard session URL info in $user_id (probably adding it after what the mod calculates)

There is a user table field that stores this, and the full URI may be stored in this field (you might need to increase the size of this field if you have too much data in the field)
Re: How can I integrate Phorum into an existing site with a single login?
July 06, 2011 06:50PM
Quote
DavidVonB
First a disclaimer, I run phorum with cookies and don't use URL authentication.

I think what may be tripping you up is
The critical bit of code is at the end of the mod
$session_data[PHORUM_SESSION_LONG_TERM] = $user_id;

I think that you need to include your standard session URL info in $user_id (probably adding it after what the mod calculates)

There is a user table field that stores this, and the full URI may be stored in this field (you might need to increase the size of this field if you have too much data in the field)

OK, I've been working on this for over a day now but I cannot get it to work.

I tried changing the parameter name Phorum uses for the URL Session (phorum_session_v5) so that it matches the parameter my main site uses (SID) by modifying line 61 in User.php but that did not work. It wouldn't show the user logged in once even if coming directly from my site. I also tried modifying the Mod so that $session_data[PHORUM_SESSION_LONG_TERM] equals the Session ID being passed on from my main site, but that did not work either. I have the suspicion that this Mod somehow affects the way Session Parameters are dealt with when no cookies are used.

From what I saw in the Phorum code, there is a lot of code handling session information and it looks quite complicated, so I am completely stuck at this point.

Perhaps one of the members of the Dev Team can chime in with their intimate knowledge of how the Sessions are dealt with for the situation I described above.

Ideally, I would like to have my main site and Phorum use the exact same Session Parameter in the URL containing the complete Session Data for both parts of the site, that way a user going back in forth already has everything stored in the Session variable obtained via the URL parameter without having to create two separate Sessions, but I have absolutely no idea how to do that.

Any ideas, folks?

Thanks a lot!
Re: How can I integrate Phorum into an existing site with a single login?
July 07, 2011 01:06AM
It'd be quite hacky to get to the point where you use Phorum's URI authentication to pass on your session ID. To make that work, you'd have to inject your session id into the Phorum user table for which to set up a session. Maybe that would work somehow, maybe not. All over I say: drop the URI authentication in total. It's a terribly insecure scheme (you already point that out yourself: copy the URL and you're in). Phorum only provides it as a final fallback, but cookies are preferred.

If you really want to keep URI auth for the main site, then I'd go for something like:

  • provide links to Phorum with the session id in the URL
  • use a mod that implements user_session_restore to pick up the session_id. This mod would:
    • check for the session id in the URL and then lookup the user info from your main site's database
    • sync the user to the Phorum database
    • setup a custom $_SESSION['user_id'] session variable to remember the user_id
    • no $_SESSION['user_id'] at this point, then no further action
    • otherwise: $session_data[PHORUM_SESSION_LONG_TERM] = $_SESSION['user_id'];

Feeding the session id to $session_data[PHORUM_SESSION_LONG_TERM] makes no sense. It needs a Phorum user_id.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: How can I integrate Phorum into an existing site with a single login?
July 13, 2011 09:17AM
Maurice, thanks for your reply, I appreciate your involvement. I also apologize for my late reply, I was away on travels and only got back this morning.

As suspected, it will require quite a bit of "hacking" to get my site - as it currently functions - to integrate seamlessly with Phorum.

Before I go down that long road - or the longer road of changing the way my site currently works - let me ask you a question to determine whether Phorum is indeed the right choice for my existing site:

Is it possible to fully embed Phorum into an existing site using dynamic PHP headers and footers from the main site? If so, how complicated is it?

Basically, I need more than just a simple HTML header/footer that will make Phorum "look" like my site. I need to be able to dynamically change both the header and footer so that the forum looks, feels, and ACTS like my site. For example, if a user is using the forum and they get a new message from the main site, my site would need to display that notice in the header of whatever page they are on.

Please let me know and thanks again, Maurice!
Re: How can I integrate Phorum into an existing site with a single login?
July 13, 2011 09:52AM
You can run each php code you want in the templates.


Thomas Seifert
Sorry, only registered users may post in this forum.

Click here to login