Firefox PHP

Integrating Phorum with my sites Users DB

Posted by daithicollins 
Re: Integrating Phorum with my sites Users DB
June 03, 2009 08:27AM
maybe you are starting a completely separate session than phorum does.
You are using session_name('..."), sure this will work with phorum ?
first try without "session_name" and "session_set_cookie_params"
Re: Integrating Phorum with my sites Users DB
June 03, 2009 07:01PM
Yep, you are right. Thanks for the advice everyone! It's up and working...
Re: Integrating Phorum with my sites Users DB
June 16, 2009 02:46PM
I am trying to integrate my existing application's user authentication with phorum.
I have done the steps described by RickM, and I too dont seem to be getting the session transferred to phorum.
I am setting $_SESSION['user_id'] in my application.

As suggested by Maurice, I have added print_r($_SESSION); to list the session variables in the function mod_phorum_User_Session_Restore.
On adding this, I see the correct value of user_id as set by my application. This means that the value of user_id session variable is correctly set when I am on the phorum page, and also that the function is being called.
In spite of that, phorum does not recognize that I am logged in.

Maurice, could you please give some suggestions on this? Is it possible that some of the steps in mod_phorum_User_Session_Restore are obsolete in the version of phorum I am using (5.2.11)? For example, this function sets the user_id value from the session variable into $data[PHORUM_SESSION_LONG_TERM] and $data[PHORUM_SESSION_SHORT_TERM]. Is it possible that these variables are named differently in the phorum version I am using?

I would really appreciate some suggestions / pointers on this issue.

Warm Regards.

P.S. I am not using "session_name" or "session_set_cookie_params"



Edited 2 time(s). Last edit at 06/16/2009 02:48PM by sonali.gupta.
Re: Integrating Phorum with my sites Users DB
June 16, 2009 03:44PM
When you have created the Phorum user with the exact same user_id as the user in your main system, then setting these fields should work. Nothing has been changed in them.

Take a look at the hook documentation for user_session_restore for a rather clean and extensively documented user_session_restore implementation. Compare that to what you have done so far. Also, double check that a Phorum user exists for the user_id that you have inside the function. A quick way to check would be code like:

Language: PHP
$user_id = $_SESSION[';user_id';]; $user = phorum_api_user_get($user_id); if (empty($user)) { trigger_error("User with user_id $user_id does not yet exist in Phorum!", E_USER_ERROR); }


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Integrating Phorum with my sites Users DB
November 15, 2009 02:11AM
I am new to Phorum (and fairly new to PHP and mySQL) but it is obviously very powerful and, as evidenced in this thread, there is an awesome support network! So first off, a big thank you to developers and Maurice whose posts have already proved invaluable to installing and modding Phorum to my current project.

The problem: I am using a slightly altered form of the script posted earlier in the thread. Phorum recognizes the session user_id and user databases are synced. However, I am consistently getting a "Cannot modify header information - headers already sent" warning stemming from my mod and it messes with the phorum/admin.php interface as well. From other threads and some googling, I deduce that I am making some sort of header call, but I can't find the problem. Can anyone spot the problem? Thanks!

Quote
modd.php
<?php


/* phorum module info
title: MySite External Authentication For Phorum
author: Me: This module allows authentication to Phorum from MySite external application
hook: user_session_restore|mod_phorum_User_Session_Restore
*/

if(!defined("PHORUM")) return;

session_start();


function mod_phorum_User_Session_Restore($data){

// This function restores the Phorum session, inherited from the site SESSION.

// We do not want to run this when we're in the admin or upgrade interface.
if (defined('PHORUM_ADMIN') || defined('PHORUM5_CONVERSION')) return $data;

global $PHORUM_CONNECTOR;

// Retrieve the user_id of the current user from the PHP session data. The user_id is really the
// only thing that needs to be remembered for a Phorum session, because all other data for the user is stored
// in the database. If no user id was set in the session, then use FALSE to flag this to Phorum.

$phorum_user_id = empty($_SESSION['user_id'])? FALSE : $_SESSION['user_id'];

// Populate the user_session_restore hook

$data[PHORUM_SESSION_LONG_TERM] = $phorum_user_id;
$data[PHORUM_SESSION_SHORT_TERM] = $phorum_user_id;

// Check tshe admin status of user, and set flags accordingly

if ($phorum_user_id) { // Find admin status by looking at Phorum "Admin" flag
// check admin flag
$user_data = phorum_api_user_get($phorum_user_id);
if ($user_data && ($user_data['admin'] > 0)) { // Admins are "1"
// user is admin
$data[PHORUM_SESSION_ADMIN] = $phorum_user_id;
}
else {
// User is not admin
$data[PHORUM_SESSION_ADMIN] = FALSE;
}
}

return $data;

}
?>





Edited 1 time(s). Last edit at 11/15/2009 01:30PM by hawaiiorganics.
Re: Integrating Phorum with my sites Users DB
November 17, 2009 06:02PM
The error means that a header is being sent (probably to set a session cookie), while body output has already been done. The headers already sent error should tell you where previous body output was done.

Possibly, you have some white-space outside <?php .. ?> in your code. In your code, I see no obvious body output.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Integrating Phorum with my sites Users DB
November 21, 2009 05:13PM
It was whitespace! THANKS! That was driving me crazy. Phorum is online and awesome!
Re: Integrating Phorum with my sites Users DB
April 06, 2010 03:09PM
Ok so i just integrated this into my site.... and well i have run into a problem... and that is whenever the UID is long it randomly puts in the numbers
"2147483647" which is causing some db errors... yah heres my code that inserts the user data.
Language: PHP
function updatePhorumUser() { global $dbh; global $uid; //Phorum // Add the new user to the Phorum users table   $curcwd = getcwd(); $dir = $curcwd . "/forum"; chdir( $dir );   define("PHORUM", 1); global $PHORUM;   //Phorum Includes   include_once("./include/db/config.php"); include_once("./include/db/mysql.php"); include_once("./include/api/base.php"); include_once("./include/api/user.php");   // Get the new MB user_id from the INSERT foreach($dbh->query("Select * From users Where uid = ';$uid';") as $row);   $Phorum_user_id = $row[';uid';]; $Phorum_Username = $row[';username';]; $Phorum_Password = $row[';password';]; $Phorum_Email = $row[';email';]; if($row[';permissions';] == "admin"){ $Phorum_Admin = 1; } else { $Phorum_Admin = 0; } //die($Phorum_user_id);   $user = array( "user_id" => $Phorum_user_id, "username" => $Phorum_Username, "password" => $Phorum_Password, "email" => $Phorum_Email, "admin" => $Phorum_Admin, "active" => PHORUM_USER_ACTIVE ); phorum_api_user_save($user, PHORUM_FLAG_RAW_PASSWORD);   chdir($curcwd); //End Phorum }
im not sure why its doing that...

note: the admin acct uid is 1 and it works fine with that
Re: Integrating Phorum with my sites Users DB
April 06, 2010 03:15PM
what size is your uid? the field is an int, seems like you are overflowing that field.


Thomas Seifert
Re: Integrating Phorum with my sites Users DB
April 06, 2010 08:41PM
i figured i out i made my uid fields in my databse int and auto increment
Sorry, only registered users may post in this forum.

Click here to login