Firefox PHP

Integration only works on first page.

Posted by KWood 
Integration only works on first page.
November 10, 2008 02:52PM
Hi
I have completed the single sign on module as found in this forum, and it works sort of....
It works when the user cliks on the link to the forum and gets the front page, user is logged in and all.
BUT when clicking on a "internal" forum link like af thread og forum group the user is now not logged in... (user rigths arent correct og th top link in log in in stead of logged in...
HELP

yours truely kwood.
Re: Integration only works on first page.
November 10, 2008 04:48PM
You cooked up some code of your own?
It might be helpful if you show us what you did so far.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Integration only works on first page.
November 11, 2008 12:37AM
Hi
this is my code:
Language: PHP
/* phorum module info title: External Login module desc: Uses Login credentials from Main site to login phorum. hook: user_session_restore|transparent_login_main */ function transparent_login_main($sessions) { // Override the session handling for front end forum sessions. // We could for example retrieve a session from a standard PHP // session by first starting a PHP session if that was // not done yet... if (!session_id()) session_start(); // print_r($_SESSION); // ...and then retrieving 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[';LMID';]) ? FALSE : $_SESSION[';LMID';];   // If we only use session inheritance for the front end // forum session (highly recommended for security), then // We keep PHORUM_SESSION_ADMIN at NULL (default value). // The other two need to be updated. If the main system does // not use the concept of one long and one short term cookie // (named "tight security" by Phorum), then simply assign // the user_id to both PHORUM_SESSION_LONG_TERM and // PHORUM_SESSION_SHORT_TERM. $sessions[PHORUM_SESSION_SHORT_TERM] = $phorum_user_id; $sessions[PHORUM_SESSION_LONG_TERM] = $phorum_user_id;   return $sessions; }



Edited 1 time(s). Last edit at 11/11/2008 04:14AM by Maurice Makaay.
Re: Integration only works on first page.
November 11, 2008 04:15AM
That looks quite good to me. So what is the output of the print_r statement when you're inside a different page than the index?


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Integration only works on first page.
November 11, 2008 01:35PM
Hi
isn't just typical... came home from work and started testing with the print_r and guess what IT WORKS!!! don't now how don't now why... but it works... but thanks for the help!
Re: Integration only works on first page.
May 21, 2009 11:50AM
I'm having the same problem
I could really use some help, I've pend days on this.
Language: PHP
<?php /* This file is used on each Phorum page to check the external application';s user session and create a session for the current user in Phorum.   Please note, that any time you want to end the script (perhaps because an error occurs) you must use the command: return $session_data;   Below is an example of various possible needs for your plugin   */   // Make sure that this script is loaded inside the Phorum environment. DO NOT // remove this line //print_r($_COOKIE); if (!defined("PHORUM")) return;   // If you need to run php code located in the external application';s server path // you can use the following code as an example   // no need to continue if the external app path is not set. if (empty($PHORUM["phorum_mod_external_authentication"]["app_path"])) return $session_data;   // save the working directory and move to the external application';s directory $curcwd = getcwd(); chdir($PHORUM["phorum_mod_external_authentication"]["app_path"]); //print_r($_COOKIE["ci_session"]); // include the necessary code from your external application //include_once("./info.php"); // get the session for the external application //$session = (!empty($_COOKIE["ci_session"])) ? $_COOKIE["external_app_session"] : $_COOKIE["ci_session"]; //$test = getcookie(); session_start(); if($_COOKIE["ci_session"]) { $session = unserialize(stripslashes($_COOKIE["ci_session"])); $_SESSION[';cip';] = $session; print_r($_SESSION[';cip';]); //echo ';cookies ';.$session; $result = mysql_query(';select * from users where id =';.$session["DX_user_id"]); if (!$result) { $user_data = array(); }else{ $row = mysql_fetch_assoc($result); //print_r($row); // get the user info from the external application //$user_data = example_get_user_funtction($session); $user_data=array("user_id"=> $session["DX_user_id"], "username"=> $row["username"], "email"=> $row["email"], "password"=> $row["password"],"admin"=>0); }   //print_r($user_data); //$user_data=array("user_id"=> $_SESSION["GO_SESSION"]["user_id"], "user_name"=> $_SESSION["GO_SESSION"]["username"], "email"=> $_SESSION["GO_SESSION"]["email"], "password"=>md5(microtime()), "admin"=>0); // if there is no user data, then no need to continue } if (empty($user_data)) { // change back to the Phorum directory chdir($curcwd); // clear the previous session in case the user logged out of the external application and Phorum login is disabled if (!empty($PHORUM["phorum_mod_external_authentication"]["disable_phorum_login"])) { //echo';clear';; $session_data[PHORUM_SESSION_LONG_TERM] = FALSE; $session_data[PHORUM_SESSION_SHORT_TERM] = FALSE; } return $session_data; }   //switch back to our working directory chdir($curcwd);   // get the api code for various user-related functions include_once("./include/api/user.php");   // it is best to use the external application';s username to authenticate to // Phorum as that should be unique and avoids the hassle of dealing with // Phorum';s serquential user_id assignment for new users $username = $user_data["username"];   // use the external username to get a Phorum user_id $user_id = phorum_api_user_search("username",$username); // then get the Phorum user data from that user_id $phorum_user_data = phorum_api_user_get($user_id); //print_r($phorum_user_data); // if the Phorum user does not exist then we need to create them if (empty($phorum_user_data)){ $phorum_user_data = array( // The user_id must be NULL to create a new user "user_id" => NULL, "username" => $username, // by transferring the password, we are ensuring that the user will be // able to login if the admin enables Phorum login "password" => $user_data["password"], // Phorum requires an email. If the external application does not, // a fake email should be used. "email" => $user_data->email, // By default, create a non-admin user. Admin status is handled later. "admin" => 0, "active" => PHORUM_USER_ACTIVE, );   // if the admin wants to automatically transfer admin status if (!empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { // and the user is an admin in the external application, then make the // phorum user an admin. Please note this is just and example. Each // application may have a different way to establish admin status if ($user_data["admin"]) { $phorum_user_data["admin"] = 1; } } // create the new user and get the user_id with which to create a session. // Please note, most applications will give you the md5 of the user';s // password. The constant PHORUM_FLAG_RAW_PASSWORD tells Phorum that the // password is already in md5. If you need to create a user with a plain // text password, simply omit the second variable in this call $user_id = phorum_api_user_save($phorum_user_data, PHORUM_FLAG_RAW_PASSWORD);   // however, if the user exists but is not active, then we should not log them in }elseif (empty($phorum_user_data["active"])){ return $session_data; // or, if the user exists, then run some check on the user';s data }else{ // if the extenal application user';s password has changed, update the phorum // user';s password if ($phorum_user_data["password"] != $user_data["password"]) { $phorum_user_data["password"] = $user_data["password"]; // save the updated user data, again with a preset md5 password $user_id = phorum_api_user_save($phorum_user_data,PHORUM_FLAG_RAW_PASSWORD); }   // if the admin wants to automatically transfer admin status and the // external user has been upgraded to admin, upgrade the phorum user, again // assuming the external application establishes admin status this way if ($user_data["admin"] && empty($phorum_user_data["admin"]) && !empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { $phorum_user_data["admin"] = 1; // save the updates user data $user_id = phorum_api_user_save($phorum_user_data); // if the admin wants to automatically transfer admin status and the // external user has been downgraded from admin, downgrade the phorum user } elseif (!$user_data["admin"] && !empty($phorum_user_data["admin"]) && !empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { $phorum_user_data["admin"] = 0; // save the updates user data $user_id = phorum_api_user_save($phorum_user_data); } }   //we have a legit user, so set there session info $session_data[PHORUM_SESSION_LONG_TERM] = $user_id; $session_data[PHORUM_SESSION_SHORT_TERM] = $user_id;   print_r($session_data); ?>
Sorry, only registered users may post in this forum.

Click here to login