Integrating Phorum with my sites Users DB
Posted by daithicollins
Re: Integrating Phorum with my sites Users DB June 03, 2009 08:27AM |
Registered: 20 years ago Posts: 11 |
Re: Integrating Phorum with my sites Users DB June 03, 2009 07:01PM |
Registered: 15 years ago Posts: 3 |
Re: Integrating Phorum with my sites Users DB June 16, 2009 02:46PM |
Registered: 15 years ago Posts: 1 |
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.
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.
June 16, 2009 03:44PM |
Admin Registered: 20 years ago Posts: 8,532 |
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:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
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



Re: Integrating Phorum with my sites Users DB November 15, 2009 02:11AM |
Registered: 15 years ago Posts: 2 |
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!
Edited 1 time(s). Last edit at 11/15/2009 01:30PM by hawaiiorganics.
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.
November 17, 2009 06:02PM |
Admin Registered: 20 years ago Posts: 8,532 |
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
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



Re: Integrating Phorum with my sites Users DB November 21, 2009 05:13PM |
Registered: 15 years ago Posts: 2 |
Re: Integrating Phorum with my sites Users DB April 06, 2010 03:09PM |
Registered: 15 years ago Posts: 2 |
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.
note: the admin acct uid is 1 and it works fine with that
"2147483647" which is causing some db errors... yah heres my code that inserts the user data.
im not sure why its doing that...Language: PHPfunction 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 }
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 |
Admin Registered: 22 years ago Posts: 9,240 |
Re: Integrating Phorum with my sites Users DB April 06, 2010 08:41PM |
Registered: 15 years ago Posts: 2 |
Sorry, only registered users may post in this forum.