User Tools


Custom User Login integration

Introduction:

The below instructions will help you to integrate FreiChat with your custom-coded site . Before going through the documentation, The guide assumes that you have successfully completed the General installation

Integrating FreiChat with any site involves three simple steps:

  • Get the ID of the logged in user.
  • Pass that ID to FreiChat.
  • Tell FreiChat the name of the “user table” along with some details.

Step 1:

Go to the file index.php(or any other) where you had copy pasted the FreiChat code.Then search for the the line $ses=null; Now you need to replace null with the userid of the current logged in user and if he is a guest you need to pass null. You can also pass any unique reference of the user instead of user id.

for eg Consider the following table structure

      ----------------------------------
      userid    username      password  
      ----------------------------------
        1        Avinash         ***
        2        Adesh           ***
        3        Francis         ***
        4        Irene           ***
      ----------------------------------

Here the userid for Avinash is 1 . Don't forget to pass null if the user is a guest or if he is not logged in. Consider the following example . Consider your file login.php

Login code

if($Username_And_Password_Match)
{
   $_SESSION['userid'] = $users['id']; // Modify to suit your requirements
 

Step 2:

Then , accordingly you need to change your copy-pasted FreiChat code as

$ses = null; // Return null if user is not logged in 
 
if(isset($_SESSION['userid']))
{ 
  if($_SESSION['userid'] != null) // Here null is guest 
  { 
   $ses=$_SESSION['userid']; //LOOK, now userid will be passed to FreiChat 
  } 
} 
 
if(!function_exists("FreiChat_get_hash"))
{ 
  function FreiChat_get_hash($ses){ . .//And the rest of the code as it is . .
 

Now suppose you set your SESSION as 0 (& not null) for guests then you will have to modify the code as shown below

if(isset($_SESSION['userid']))
{ 
  if($_SESSION['userid'] == 0)
  { 
     $ses = null; //Declare him as guest 
   } 
}

You can also use COOKIE or any other complicated query to get the userid .

Step 3:

1. Go to the path you had unzipped the freichat folder . for convenience i will assume the path to freichat folder to be ~/freichat/

2. Go and edit the file ~/freichat/hardcode.php

Requirements : You need to have a table which stores the logged in users' name And his userid or any unique reference which will be treated as his id.

Process : Now I assume a simple eg. where user info is stored in the table 'user_info' and the user_name is stored in a field named 'username' and the id is stored in a field named 'userid'

Sample table structure :

        -------------------------------
        userid    username    password
        -------------------------------
          1       Avinash        ***
          2       Adesh          ***
          3       Francis        ***
          4       Irene          ***
        -------------------------------

You may use any type of complicated user table , but we are only interested in the above two fields.

Here the field name where the user_name is stored is username and the field name where the user's id is stored is userid

3. Now search for the following three lines in your ~/freichat/hardcode.php

$usertable="login"; //specifies the name of the table in which your user information is stored. 
$row_username="root"; //specifies the name of the field in which the user's name/display name is stored. 
$row_userid="loginid"; //specifies the name of the field in which the user's id is stored (usually id or userid)

Now replace the word login with you name of the table i.e user_info and the word root with username and loginid with userid So it will now look like

$usertable='user_info'; //specifies the name of the table in which your user information is stored. 
$row_username='username'; //specifies the name of the field in which the user's name/display name is stored. 
$row_userid='userid'; //specifies the name of the field in which the user's id is stored (usually id or userid)

The index's user_info username & userid that are used above are only for explanatory purpose , you may have to modify it according to your table/code.

This will integrate FreiChat with your websites login system.