[Tutorial] Custom integration using cms.php

<<

NetSurfer

Moderator

Posts: 2513

Joined: Sat Apr 12, 2008 12:43 pm

Location: England, UK

Post Mon Mar 14, 2011 1:45 pm

[Tutorial] Custom integration using cms.php

... heres a quick explanation on how to create auto login for content systems,

When a member logins into your content management system (CMS for short), normally several login values are stored as PHP session values ($_SESSION). These values are unique to the logged in user, so what we can do is use these values and enter them into the 'prochatrooms/cms.php' file. This allows us to auto-login to the chat room without entering our login details twice as long as we are logged into the content system.

How can we find out what these values are?

... actually is very easy to do even if your a newbie to all this technical stuff, just open your notepad (or any text editor) then copy and paste the code below and save the file as 'showSessions.php'.

  Code:
<?php
session_start();

/** Show Session Values **/
foreach($_SESSION as $key => $val)
{
   echo $key . " : " . $val . "<br>";
}

?>


Now upload the 'showSessions.php' file to your server and login to your content system. After logging in, type the url in your browser address bar to the 'showSessions.php' file. You should now see a white page with a list of data in it, something like,

username : somename
userid : 123


... there could be more details but thats the 2 that are the most important (the ones you need to use are username and userid, they might be slightly worded differently, eg instead of userid it might be uid but you should be able to tell which is the username and which is the userid values). Note: If the 'showSessions.php' file is blank (eg. nothing is displayed on the page), then you can stop reading this tutorial as my advice here wont be able to help you integrate the chat room with your content system, sorry about that.

Now we have these values, lets enter them to our 'prochatrooms/cms.php' file,

1) Open the file 'prochatrooms/cms.php' and enable this setting,

  Code:
// Enable custom login details

define('C_CUSTOM_LOGIN','1'); // 0 OFF, 1 ON


2) Now we enter the values for the users name and id (remember how we found out what this was by using the 'showSessions.php' file?),

// Enter your CMS Global values below

define('C_CUSTOM_USERNAME',$_SESSION['username']); // username
define('C_CUSTOM_USERID',$_SESSION['userid']); // userid

if(!isset($_SESSION['userid']) || isset($_SESSION['userid']) < 1)
{
die("Please login from the main website");
}


3) Open the file 'prochatrooms/include/config.php' and edit the settings shown so they match below,

  Code:
/*
* integrated with CMS
* allows users to auto-login
*/

$CONFIG['CMS'] = '1'; // 0 No, 1 Yes

/*
* enable guest mode
* allows guests to login to chat room
*/

$CONFIG['guestMode']  = '0'; // 0 No, 1 Yes - allow guests to login


Now (in theory and assuming you have entered the correct values for the username and userid), the values for the username and userid are 'hardcoded' into the Pro Chat Rooms and as long as the user is logged into your CMS they will be auto logged into the chat room.

To link to your chat room and auto log your members in, use the url below.

  Code:
http://www.yoursite.com/prochatrooms/


Yep, thats it, easy eh? This replaces the original javascript method for integration and once fully understood, its incredibly easy to do.
Last edited by NetSurfer on Wed Jul 25, 2012 2:38 pm, edited 10 times in total.
Reason: added check session is set in step 2, prevents blank windows/userlist when not integrated correctly
About this forum,
  • Search option isnt just there to look pretty, its your fastest solution.
  • Sorry guys, but please do not PM me for help. It helps everyone if you post your questions in the forum as other users may be too shy to ask! lol
Need more help? - Read the tutorials,
This is a user to user forum, please help this community by helping others. :)
<<

ThomMyers

Junior Member

Posts: 12

Joined: Mon Apr 21, 2008 2:23 pm

Post Wed Apr 06, 2011 9:39 pm

Re: [Tutorial] Custom integration using cms.php

I followed these instructions and I'm able to login to the v7.0 chatroom through our WordPress 3.1.1 but the chatroom doesn't work I can't post messages, my name doesn't appear in the user list, there aren't any rooms in the drop-down and none of the smilies or SFX work and clicking the Avatars menu item doesn't do a thing. The same problems occur regardless of whether I login as a regular Member group user or as a full-permission Admin group user. It does let me Disconnect though:

IE8 gets this script error:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6.6; chromeframe/10.0.648.204; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MS-RTC LM 8; .NET CLR 1.1.4322)
Timestamp: Wed, 6 Apr 2011 21:24:48 UTC

Message: Syntax error
Line: 31
Char: 14
Code: 0
URI: http://theworldofblues.com/prochatrooms/

Message: 'publicWelcome' is undefined
Line: 21
Char: 2
Code: 0
URI: http://theworldofblues.com/prochatrooms/js/functions.js
<<

NetSurfer

Moderator

Posts: 2513

Joined: Sat Apr 12, 2008 12:43 pm

Location: England, UK

Post Thu Apr 07, 2011 11:58 am

Re: [Tutorial] Custom integration using cms.php

... another way instead of using the cms.php file (still using the same method tho) is to open the file 'prochatrooms/index.php' and find this,

  Code:
/*
* cms integration
*
*/

if($CONFIG['CMS'] && !isset($_GET['logout']))
{


Under that remove this code,

  Code:
   // cookie login
   if($_REQUEST['uname'])
   {
      // unset login
      unset($_REQUEST['login']);

      // assign user details
      $_SESSION['username'] = $_REQUEST['uname'];
      $_SESSION['userid'] = $_REQUEST['uid'];
   }

   // session login
   if(!$_SESSION['username'])
   {
      // include files
      include("cms.php");

      // session login
      if(C_CUSTOM_LOGIN && $uname)
      {
         // assign user details
         $_SESSION['username'] = $uname;
         $_SESSION['userid'] = $uid;
      }

   }


... and replace with,

$_SESSION['username'] = $_SESSION['foo_name'];
$_SESSION['userid'] = $_SESSION['foo_id'];

if(!$_SESSION['member_name'])
{
die("Please login via the main website.");
}


... remember to replace the values in red with your CMS session values, you could go one step further with this and use a db query to get the CMS user details instead if you prefered.

NOTE: always remember to clear the chat room user table when testing auto login (admin area > database > truncate > users table), it will avoid any empty values in the table which might cause problems.
About this forum,
  • Search option isnt just there to look pretty, its your fastest solution.
  • Sorry guys, but please do not PM me for help. It helps everyone if you post your questions in the forum as other users may be too shy to ask! lol
Need more help? - Read the tutorials,
This is a user to user forum, please help this community by helping others. :)
<<

ThomMyers

Junior Member

Posts: 12

Joined: Mon Apr 21, 2008 2:23 pm

Post Fri Apr 08, 2011 2:32 am

Re: [Tutorial] Custom integration using cms.php

It turns out I didn't enter the username and userid in step 2 in your first set of instructions. Now I have two questions:

1. Do you know what exact username and userid variables are used by WordPress 3.1.1? My guess is:
username is user_login
userid is ID

2. I'm fairly certain your not but I just want to make sure. Are you depending on REGISTER_GLOBALS being turned on? Because that's not going to happen. To much of a security risk on the server.
<<

NetSurfer

Moderator

Posts: 2513

Joined: Sat Apr 12, 2008 12:43 pm

Location: England, UK

Post Fri Apr 08, 2011 7:12 am

Re: [Tutorial] Custom integration using cms.php

ThomMyers wrote:1. Do you know what exact username and userid variables are used by WordPress 3.1.1? My guess is:
username is user_login
userid is ID

... not sure what the session values are, sorry.


ThomMyers wrote:2. I'm fairly certain your not but I just want to make sure. Are you depending on REGISTER_GLOBALS being turned on? Because that's not going to happen. To much of a security risk on the server.

... hell no!, dont enable register globals or safe mode, both should be disabled for security.
About this forum,
  • Search option isnt just there to look pretty, its your fastest solution.
  • Sorry guys, but please do not PM me for help. It helps everyone if you post your questions in the forum as other users may be too shy to ask! lol
Need more help? - Read the tutorials,
This is a user to user forum, please help this community by helping others. :)
<<

odonel

Senior Member

Posts: 239

Joined: Mon Sep 29, 2008 2:54 pm

Post Tue Apr 12, 2011 6:37 pm

Re: [Tutorial] Custom integration using cms.php

hey surf, in my CMS, my userid is like this $userid=$vbulletin->userinfo['userid']; how come when a user enters the room, prochat is not using the ID from vbulletin. The UID is not equal to ID in profile...
e.g, a user has ID 3020 in VB, but prochat is assigning ID 6 to that user...
<<

Alicia

Senior Member

Posts: 74

Joined: Mon Dec 07, 2009 4:15 pm

Post Wed Apr 13, 2011 2:57 am

Re: [Tutorial] Custom integration using cms.php

odonel wrote:hey surf, in my CMS, my userid is like this $userid=$vbulletin->userinfo['userid']; how come when a user enters the room, prochat is not using the ID from vbulletin. The UID is not equal to ID in profile...
e.g, a user has ID 3020 in VB, but prochat is assigning ID 6 to that user...

I believe I had the same issue with phpbb. You could probably adapt the fix for vB easily enough: viewtopic.php?p=5329#p5329 and/or further down: viewtopic.php?p=5342#p5342

It will still assign the user a chat userid but it will use the vB id when accessing profiles. If you look at your SQL database you'll probably see it's storing the vB userid but also designating a chat ID... It's rather weird but it will work out.
<<

odonel

Senior Member

Posts: 239

Joined: Mon Sep 29, 2008 2:54 pm

Post Wed Apr 13, 2011 1:15 pm

Re: [Tutorial] Custom integration using cms.php

not working for me surf... when i modified the functions file, it reverts me to login.php everytime i try to login... if i edit the userlist, the userid is undefined in vb
<<

NetSurfer

Moderator

Posts: 2513

Joined: Sat Apr 12, 2008 12:43 pm

Location: England, UK

Post Wed Apr 13, 2011 1:25 pm

Re: [Tutorial] Custom integration using cms.php

... which functions file?
About this forum,
  • Search option isnt just there to look pretty, its your fastest solution.
  • Sorry guys, but please do not PM me for help. It helps everyone if you post your questions in the forum as other users may be too shy to ask! lol
Need more help? - Read the tutorials,
This is a user to user forum, please help this community by helping others. :)
<<

odonel

Senior Member

Posts: 239

Joined: Mon Sep 29, 2008 2:54 pm

Post Wed Apr 13, 2011 2:47 pm

Re: [Tutorial] Custom integration using cms.php

functions.php from the link you referred me to
Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest