PHPMaker 5.0 + Simple Machines Forum SMF 1.1.8 Integration
May 16th, 2008 - Ryan ChristensonThe following tutorial is for integrating PHPMaker 5.0 (generated web files) with Simple Machines Forum 1.1.8. This tutorial is for integration between PHPMaker generated website files and SMF 1.x.x forum software.
There’s also an older PHPMaker 4.3 + SMF 1.1.8 Tutorial available.
Please note the SMF package is no longer available for download. The following tutorial is for a manual install.
Note: You can use the SSI Login and Welcome functions for a register link in your PHPMaker template (open up ssi_examples.php from your forum folder to view examples and additional information).
Prerequistes:
SMF Files To Modify (2):
- smf_forum_folder\Sources\Load.php
- smf_forum_folder\Sources\LogInOut.php
Step #1 – Turn off Database Driven Sessions (In SMF)
A. Find the following option in SMF:
Admin –> Server Settings –> Feature Configuration –> Use database driven sessions
B. Make sure, “Use database driven sessions” IS UNCHECKED. This integration will not work with database sessions on.
Step #2 – Security Settings (In PHPMaker)
A. Security -> Use Existing Table ->
Table = smf_members
Login Name Field = memberName
Password Field = passwd
B. Hit Advanced tab, change User Level field to userlevel
C. Right click to add user level, name it Registered
D. Choose permissions you want this userlevel to have (This will be for normal users)
E. Edit/Add any other userlevels as you wish
F. Generate PHPMaker code
G. Download and use the package or continue on with the following steps.
Step #3 – Use the following query in phpmyadmin to Add userlevel field to smf_members table:
ALTER TABLE smf_members
ADD userlevel int(2) NOT NULL default ‘1′;
Note: This query will make all future accounts in smf as “normal” setting with PHPMaker. If you would like someone to have admin privileges you can manually change this in the database or setup a separate table in PHPMaker to control this in the backend.
Step #4 – Make Changes In LogInOut.php
———-
Find this line 2 times:
SELECT passwd, ID_MEMBER, ID_GROUP, lngfile, is_activated, emailAddress, additionalGroups, memberName, passwordSalt
Change both to:
SELECT passwd, ID_MEMBER, ID_GROUP, lngfile, is_activated, emailAddress, additionalGroups, memberName, passwordSalt, userlevel
———-
Next Find:
// Bam! Cookie set. A session too, just incase.
setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['ID_MEMBER'], sha1($user_settings['passwd'] . $user_settings['passwordSalt']));
Add after:
Note: The use of “smf” below is where the name of your project should be.
// PHPMaker 5 & SMF Integration Start
$_SESSION[smf_status_UserName] = $user_settings["memberName"];
$_SESSION[smf_SysAdmin] = 0; // Non System Administrator
$_SESSION[smf_status_UserID] = $user_settings["memberName"]; // User ID
$_SESSION[smf_status_UserLevel] = $user_settings["userlevel"]; // User Level
$_SESSION[smf_status] = “login”;
if ($_SESSION[smf_status_UserLevel] == -1) { // System Administrator
$_SESSION[ofdb5_status_UserID] = -1;
}
// PHPMaker 5 & SMF Integration End
———-
Next Find:
// Empty the cookie! (set it in the past, and for ID_MEMBER = 0)
Add right before:
// PHPMaker 5 & SMF Integration Start
@session_unset();
@session_destroy();
// PHPMaker 5 & SMF Integration End
———-
Step #5 Make Changes In Load.php
———-
Find:
// Is the member data cached?
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < 2 || ($user_settings = cache_get_data('user_settings-' . $ID_MEMBER, 60)) == null)
{
$request = db_query(“
SELECT mem.*, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = $ID_MEMBER)
WHERE mem.ID_MEMBER = $ID_MEMBER
LIMIT 1″, __FILE__, __LINE__);
$user_settings = mysql_fetch_assoc($request);
mysql_free_result($request);
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
cache_put_data(‘user_settings-’ . $ID_MEMBER, $user_settings, 60);
}
Add After:
Note: The use of “smf” below is where the name of your project should be.
// PHPMaker 5 & SMF Integration Start
define(“smf_status_UserName”, “smf_status_UserName”);
define(“smf_SysAdmin”, “smf_SysAdmin”);
define(“smf_status_UserID”, “smf_status_UserID”);
define(“smf_status_UserLevel”, “smf_status_UserLevel”);
define(“smf_status”, “smf_status”);
$_SESSION[smf_status_UserName] = $user_settings["memberName"];
$_SESSION[smf_SysAdmin] = 0; // Non System Administrator
$_SESSION[smf_status_UserID] = $user_settings["memberName"]; // User ID
$_SESSION[smf_status_UserLevel] = $user_settings["userlevel"]; // User Level
$_SESSION[smf_status] = “login”;
if ($_SESSION[smf_status_UserLevel] == -1) { // System Administrator
$_SESSION[ofdb5_status_UserID] = -1;
}
// PHPMaker 5 & SMF Integration End
———-
That’s all folks! If you have any questions, comments or need help with the integration then comment away!
Tags: Forum, Integration, PHP, PHPMaker, SMF Forum, Tutorials


June 27th, 2008 at 10:27 AM
This code worked perfectly on my website. Although I was using it to integrate my website with SMF, it still worked very well. I just tweaked it to suit my needs and now I get exactly what I want. I’ve had a post on SMF that never got a response and I also searched SMF for an answer to my problem, but no response ever arose that fully explained it as well as this page.
Thanks
June 28th, 2008 at 2:19 AM
@SauloA Glad to hear it! Hopfully I’ll get around to writing it for SMF 2.0. I still have yet to look at the code.