CodeIgniter Chat example

Comments (175)
  1. suresh says:

    It was not working for us. there is no db file and corect file structure and html. Please provide us remaining or full code

    1.  Actually I forgot to add it.Now I added it.You can see it in the “Later added” part.Thanks for the remind it.

  2. raullrich says:

    Could you upload de code user_model please ?

    1.  I re-uploaded files with user_model and database file.Download it from above link.

  3. Behattieu says:

    It was not working, Plase help me, how to confige routes file to first run website (it’s default: $route[‘default_controller’] = “welcome”; ),
    (tree folder following)  ,

    1. -Set the main page name(welcome) in the routes.php files set as follows.
      $route[‘default_controller’] = “welcome”;
      Welcome is the controller name.So you need to set correct view file path in that main welcome controller .
      EX:- view file name – welcome.php. This is locate in the main view folder(you can change it.).Then set this path as follows in the welcome controller.(welcome.php)
      public function index()

      routes.php ——-> $route[‘default_controller’] = “welcome”;

      welcome.php comtroller file ———->
      public function index()

      Set these configurations in the config.php file.
      $config[‘hostname’] = “localhost”;
      $config[‘db_username’] = “root”;
      $config[‘db_password’] = “123456”;
      $config[‘db’] = “codeigniter_demo”;

      create chat table and run the site as http://localhost/demoChat/welcome/

      1. Behattieu says:

         file welcome in controller: public function index()
        file config/database.php
        $db[‘default’][‘hostname’] = ‘localhost’;
        $db[‘default’][‘username’] = ‘root’;
        $db[‘default’][‘password’] = ”;
        $db[‘default’][‘database’] = ‘zerostr_zero’;

        when i run this site http://localhost/demoChat/ then display error:

        A PHP Error was encountered

        Severity: Notice
        Message: Undefined variable: UsersList
        Filename: chat/users_list.php
        Line Number: 51

        Fatal error: Call to a member function result() on a non-object in C:xampphtdocsdemoChatapplicationviewschatusers_list.php on line 51

        User Id
        User Name
        …….please help me,
        Thanks Advanced/

        1. You need to define this variable in the current controller.This is a basic error in the codeigniter. You can refer the codeigniter official site to get and display values from controller to view.So in here, need to get current users name list from controller and display it in the view page.
          function index()


          //Get all users list using user_model
          $this->outputData[‘UsersList’] = $this->user_model->getUsers();

          //Load the users list view

          In the users_list.php file getting this variable values as an array and display it.
          foreach($UsersList->result() as $Users){
          Users names here


          1. Behattieu says:

             Thank you very much for your helps,I have run successful website.I tried to design the table users and roles for testing your program, but did not succeed.can you send me the database structure of the table users and roles.I thank you for that.p / s: I am a newbie.        You do not laugh.

          2. You can see the database file in the full source code you have downloaded.

          3. Behattieu says:

             Question 1: I changed Paths in js/chat.js
     to   http://localhost/demoChat/applicationviews/chat/chat.php?action=   .
              But not active. I run website and after click to link username (on display user_list file) then nothing appear.

            Question 2:
            in CodeIgniter then Is it allow character like:  “chat.php?action= …”  in Ajax Url variable,



          4. praso says:

            hi thanks! for the code

            it works fine on my WAMP – localhost , BUT when i tried on server (ONLINE) –> all worked well but when i click on anyone’s name then NOTHING happen.

            I can see whether users are “active”/”inactive” but the problem in chat pop-up (may be in jquery), so please help.

            thanks in advanced.

          5. -First you need to change all urls I have told as in this article(specially chat.js file,chat.php file).
            -You need to put jquery file and then its path as I said.Then try it.

            -Check whether CI is allow to direct path access in the server.If not remove the all codes in the application/.htaccess file.(not suitable) . Or you can give correct file paths and allow to access them.


          6. praso says:

            thanks! it worked….but

            when i upload them on my server (online) everything works fine but:-

            1. it says “undefined” in place of my name ($from)
            (check attached jpeg)
            2. also there is no entry in database.

            also i changed all the urls in chat.js and also i have correct entries of my database in view/chat.php.

            plz reply

            thanks in advance

          7. This is happening not saving codeigniter session properly.Check your session variables and check it’s username.When session username is empty, then you can see this as “undefined” . You can see in the chat table, from field is empty.That is because of this issue.
            Then check config.php file for following configurations.

            $config[‘sess_cookie_name’] = ‘ci_session’;
            $config[‘sess_expiration’] = 7200;
            $config[‘sess_expire_on_close’] = FALSE;
            $config[‘sess_encrypt_cookie’] = TRUE;
            $config[‘sess_use_database’] = FALSE;
            $config[‘sess_table_name’] = ‘ci_sessions’;
            $config[‘sess_match_ip’] = FALSE;
            $config[‘sess_match_useragent’] = TRUE;
            $config[‘sess_time_to_update’] = 300;

            In the above, $config[‘sess_use_database’] = FALSE; Then session data not saving. Keep it FALSE.


          8. praso says:

            thanks for your quick reply!

            first of all there is no problem in your code but i have to integrate it with my website which requires login.

            There is no problem in chat pop and also now it shows user name instead of “undefined”. Also now all the chat entries are saved in DB.

            But there is only one way communication i.e. although both can send the chat but only one can receive the chat.

            i know there is no problem in your code and there is some mismatch when I integrate your code with my website. I really appreciate your code and I know there is some slight problem on my side but I cant find that loophole.

            Waiting for your reply.

            Thanks in advanced.

          9. GIL says:

            Hello I have same problem with CI and the SESSIONS, “Undefined !” Do you have a solution ? please 🙂

          10. Check the set session start in the users view file.

            $_SESSION[‘username’] = $this->session->userdata(‘username’);

            Check the config.php file for following details are same as follows.
            $config[‘sess_cookie_name’] = ‘ci_session’;
            $config[‘sess_expiration’] = 7200;
            $config[‘sess_expire_on_close’] = FALSE;
            $config[‘sess_encrypt_cookie’] = TRUE;
            $config[‘sess_use_database’] = FALSE;
            $config[‘sess_table_name’] = ‘ci_sessions’;
            $config[‘sess_match_ip’] = FALSE;
            $config[‘sess_match_useragent’] = TRUE;
            $config[‘sess_time_to_update’] = 300;


          11. GIL says:

            Hi, thank I try your solution now 🙂

          12. Hi,
            application/views/chat/chat.php –> add “@” mark before the mysql_query as follows.
            Hope this work and this is may be in the wamp new server.

          13. naya says:

            it’s not working… i need the Full source code containing with users login and logout process. i try to download it but i receive nothing in my email and (thanks alot )

          14. Every about 2 seconds, checking chat data via ajax. It is going like :-http://localhost/CodeIgniter/application/views/chat/chat.php?action=chatheartbeat ………… etc.

            First you need to change all urls I have told as in this article.
            You need to put jquery file and then its path as I said.Then try it.


  4. John Sam says:

    Can you post users table structure? I can’t test your program.

    1. Here is the users table structure…

    2. This is the new and simple table structure after re-posted this article.

  5. Faysal says:

    Fatal error: Class ‘Controller’ not found in D:xampphtdocssearchapplicationcontrollerschat.php on line 15

  6. Faysal says:

    Fatal error: Class ‘Controller’ not found in D:xampphtdocssearchapplicationcontrollerschat.php on line 15

    1. is my controller name.So you can put your own controller name.The defalut controller name is CI_Controller . You can try like this.

      class Chat extends Controller
      class Chat extends CI_Controller


  7. Alex says:

    Thank you very much !

    I put and run full source code.Worked chat process very well. Demo is perfect.Can I drag the chat boxes?
    I find CI chat example every where. Finally I found correct place.You saved my time.Thanks again!

    1. Heer Shah says:

      plz send me full sourcecode of this project..bcz i cant sucessfully run this project…….plz help me

        1. Heer Shah says:

          how to run this program properly sir plz help me…….

          1. If you know to configure the codeigniter then configure the full source code. there is the database too.


          2. Heer Shah says:

            sir when i open Directory access is forbidden.error occure

          3. if you run the localhost try to remove htaccess file on application folder.Why do you want to access directory from browser?

  8. pradeep says:

    Thanks for the code… I implemented everything and worked like a charm.. But, I have one issue, while chatting, if I close the chat box (no logout), and someone sends chat, the chat box opens, thats fine.. but, all chat message shows up (there is already few text in chat box, and seems, that already chat message again comes from database).

    1. That displaying chat history is normal process of the chat.For a example, you know automatically load chat history in the facebook chat box/gmail.

      You can try to comment or modify views/chat/chat.php file, line 151 as follows.
      foreach ($_SESSION[‘openChatBoxes’] as $chatbox => $void) {
      // $items .= chatBoxSession($chatbox);

      Then not loading chat history.


  9. yugal says:

    A Database Error Occurred

    Error Number: 1046

    No database selected

    SELECT ci_users.user_id, ci_users.user_name, ci_users.user_email,
    FROM (ci_users)
    WHERE ci_users.user_id = 0
    ORDER BY ci_users.user_id asc

    Filename: C:wampwwwcodeignitersystemdatabaseDB_driver.php

    Line Number: 330

    1. Check your database details, connection and that select or not your database. app/config/config.php file.

      1. pad says:

        I am also seeing the same error,database configuration looks fine.

        A Database Error Occurred

        Error Number: 1046

        No database selected

        SELECT ci_users.user_id, ci_users.user_name, ci_users.user_email, FROM (ci_users) WHERE ci_users.user_id = 0 ORDER BY ci_users.user_id asc

        Filename: C:wampwwwgoodchatsystemdatabaseDB_driver.php

        Line Number: 330

        1. I forgot to tell to check same database details in the app/views/chat/chat.php file :
          define (‘DBPATH’,’localhost’);
          define (‘DBUSER’,’root’);
          define (‘DBPASS’,”);
          define (‘DBNAME’,’codeigniter’);


          1. pad says:

            DB details in chat.php is also fine, looks like i am missing something?

          2. pad says:

            Another observation is DB_driver.php also requires similar DB details, looks like its missing there as well.

            Unfortunately, for me even updating this file is also not helping !!!

          3. Better way is configure the application codeigniter without process of chat files.It think there are/is simple mistake in your codeigniter application. If no errors, then add your chat files and check it. I tested this chat process more than 10 times without any errors.So try to follow above instructions.


          4. pad says:

            If I keep the default database.php values such as

            $db[‘default’][‘hostname’] = $CI->config->item(‘hostname’);

            $db[‘default’][‘username’] = $CI->config->item(‘db_username’);

            $db[‘default’][‘password’] = $CI->config->item(‘db_password’);

            $db[‘default’][‘database’] = $CI->config->item(‘db’);

            it works fine.

            Should’nt these database values point to my DB details instead?

          5. pad says:

            Yet another obsevation is that on the webserver I see no chat messages are displayed nor sent, however chat messages gets recorded in database ( chat table), any idea whats going wrong here?


  10. Aleena says:

    Thank u very much for the code….
    when i integrate it with my code, the entire chat history automatically appended to chat window in an interval. will you please help me to correct that.

  11. Aleena Joseph says:

    Thank u very much for the code….

    when i integrate it with my code, the entire chat history automatically
    appended to chat window in an interval. will you please help me to
    correct that.

    1. That feature is normal process of the chat.For a example, you know automatically load chat history in the facebook chat box.
      You can try to comment or modify views/chat/chat.php file, line 151 as follows.
      foreach ($_SESSION[‘openChatBoxes’] as $chatbox => $void) {
      // $items .= chatBoxSession($chatbox);

      Then not loading chat history.


      1. Aleena Joseph says:

        In my code, I reload the user list using ajax for find online users. so userlist automatically refreshed in every 5 sec. At that time chat history also again appended with above history. Actually I want chat history but in my code it repeat in every 5 sec.

        When I try to solve this ,I close and again open chat box in checkChatBoxInputKey() and in chatHeartbeat() before appending the history. but the problem still arise when I receive msg from another window. Will u pls help me…. And Thanks for the reply

  12. Moon says:

    Hi Sumith Harshan, I can’t download you chatting script.When click on the “Download Full Codeigniter Chat Example ” button ,its redirect me another page.
    Please help me,or send me all script on my mail id “”.
    Thanking You


    1. Hi dear,
      After clicked Download button, it goes to the new page.After 5 seconds you can see “SKIP AD” yellow color button top right corner in the page.Click on it.Then you can download the full source code.


  13. Ram says:

    hi i’m not able to download the source code..when i click on your download link it takes me to the ad fly page which is just blank and i’ve got nowhere to go from there your help would be greatly appreciated. Thanks in advance

    1. After click on the download button it goes to linkbucks site and click on “skip this add” Button.It goes to the adfly page. After 5 seconds click “Skip Add” button.Then you can download the full source code. I checked it. Download is working fine.


      1. Ram says:

        in the ad fly page nothing comes up even if you wait for a min..can u ask anyone else to check it whether they can download it..i jus tried it’s not working it’s d same for many of your downloads..thanks..

        1. I’ll send the link to download.

          1. Ram says:

            that is the exact link which is not working..i dont any extensions or add ons dat’s blocking it..can u pls giv me d direct link without the ad fly..

            Send the email address. I’ll send the files.

          3. Ram says:

            thank it now..

  14. gaurang says:

    your code not fill history in chatbox when we open it first time like facebook chatbox fill the previous chat i changed in jquery and customised it but though it not show me history..any suggestion would be appreciate..Thanks.

  15. saghar says:

    users_model.php is not complete 🙁
    there werent 2 function

    1. Hello saghar.
      Can you tell me what are the missed functions on that file. Because the download source code is a copy of the demo files. I checked by comparing them. No any missed functions.


  16. renzo says:

    hi I encounter this error everytime i click the lUsers Login link.

    “Fatal error: Call to a member function num_rows() on a non-object in C:xampphtdocschichatapplicationmodelsusers_model.php on line 69”


    1. Hi,

      This is related to the getLoggedInUser() function in this model.In there, checking logged users details and return it.It is getting data from the session. Did you check the session is working fine and config settings are correct or not?

      If everything are ok, then simply check if session user id empty or not in that function.
      function getLoggedInUser()

      $user = ”;

      if($this->session->userdata(‘user_id’) !=”) {
      $condition = array(‘ci_users.user_id’=>$this->session->userdata(‘user_id’));
      $fields = ‘ci_users.user_id,ci_users.user_name,ci_users.user_email,’;

      $query = $this->getUsers($condition,$fields);

      $user = $query->row();

      return $user;


  17. Sujan says:

    I can’t get the chat room while clicking on the username. I am using jquery 1.9.1, is this the problem?

    1. Hi. Thanks for the reading my post.When you clicked on the username it call to the chatWith(chatuser) function in the chat.js file. It is getting the user name and do the chat process. I added to that file jQuery.noConflict() function.

      First check the user name is loaded into that function as following.

      onClick=”javascript:chatWith(‘user_name; ?>’);”

      Then add jQuery.noConflict() function top of the file.

      Let me know your response.


      1. Sujan says:

        Is this compulsory to use jQuery.noConflict()? I have deleted this line from the code. While doing this the css part for the initial chat room doesn’t read…can you help me with this

      2. Sujan says:

        while placing the jQuery.noconflict() then got error of $ is not a function of other jquery function what to do. Please give some suggestion on this topic?

        1. That is simple error.Put the $ symbol into the function as following in the chat.js file.

          jQuery(document).ready(function( $ ){

          More info:

          1. Sujan says:

            now all the error about jquery is solved, but the error is why I’m not getting full chat history while clicking the user name. I have change the username to user id.Is this the problem?

      3. sujan says:

        about history…history only extracts the other message only..Im not getting the message i send…why?

  18. mm says:

    Call to a member function where() on a non-object in C:wampwwwchatnewapplicationmodelsusers_model.php on line 31

    showing this error.. how can i correct it?

    1. mm says:

      plz rply asap 🙁

      1. Hi,
        can you check when you call to function getUsers() you passed the where condition to it?

        If correctly added then add the following code after this code.


        need to add after here.
        function getUsers($conditions=array(),$fields=”)


        When you add it look like this.

        function getUsers($conditions=array(),$fields=”)


        Save and run.


        1. mm says:

          thank you for your reply..this solved the issue.. but now i’m stuck somewhere else i have a js folder with js file in it..and in chat.js when i give this url ” http://localhost/chatnew/application/views/chat.php?action=chatheartbeat” , it gives me an error saying network error 403 .. please tell me what’s wrong here?

          1. mm says:

            Also i have included js file in userList.php but still it doesn’t seem to work ..please help

          2. mm says:

            Do i have to redirect ithe url in chat.js to a controller first?

  19. Nafis says:

    hi sumit the download link not working. From where i can download the code

    1. After submit your email you can get an email with download link.Here is the download link too.


      1. Nafis says:

        Hi Sumit,

        The link is not working again. When i click on link a page is open and when i click on Skip Add button a blank page is open. Could you please send me the zip file.



        1. Hi,
          May be not allow to download to your country.Here is the link to download.

          Let me know this is not working.

          Sorry for the inconvenience.

          1. Nafis says:

            Hi Sumith,
            Again the link is not working.


          2. I think the both download links are not allow to your country.Sorry for the inconvenience.
            If you want to download other files you can visit my site via proxy server.

            I have sent full source code to your email address.


  20. Prince Mahendra Sharma says:

    Thanks Buddy…..
    code worked for me…….

  21. Prince Mahendra Sharma says:

    hello sumit…
    i need ur help…

    $config[‘sess_cookie_name’] = ‘ci_session’;
    $config[‘sess_expiration’] = 7200;
    $config[‘sess_expire_on_close’] = FALSE;
    $config[‘sess_encrypt_cookie’] = TRUE; // This must be TRUE
    $config[‘sess_use_database’] = FALSE; // This must be FALSE
    $config[‘sess_table_name’] = ‘ci_sessions’;
    $config[‘sess_match_ip’] = FALSE;
    $config[‘sess_match_useragent’] = TRUE;
    $config[‘sess_time_to_update’] = 300;

    if i want to keep $config[‘sess_use_database’] = FALSE;…… TRUE…….

    then what what to do ???

    Actually i need to save session data in database….
    right now i is showing undifined at the place of $from….
    plz reply

  22. yoga kumboro says:

    hi smith, thanks 4 the code..
    I had the problem when implement your code:
    the page and chatbox work fine, but when I type some text & then send it nothing happend, no text appeared in the chatbox
    need ur help plz

    1. Can you check the database details are correctly entered and chat.js file each urls?

      1. yoga kumboro says:

        the message not saved in chat table…

        1. Check the same database details in the app/views/chat/chat.php file :-
          define (‘DBPATH’,’localhost’);
          define (‘DBUSER’,’root’);
          define (‘DBPASS’,”);
          define (‘DBNAME’,’codeigniter’);

      2. yoga kumboro says:

        solved, I’ve traced in chat.js, line 224,
        thanks alot Sumith

  23. deepak says:

    I did every thing perfectly according to you but i am not able to chat only chat window is open but not able to get massage and send massage

    1. You can check response using firebug console when you are sending messages.If response url is not found check chat.js file relevant paths.Also check the db details , chat.php file db details too.


    2. yoga kumboro says:

      check chat.js in line 224 ;).
      adjust to your url application

  24. yoga kumboro says:

    I tried to combine your code with my application in my company, unfortunately my company using ms sql server.
    I strugled to change some part of your code in chat.php in views folder, but still failed.

    define (‘DBPATH’,’localhost’);
    define (‘DBUSER’,’root’);
    define (‘DBPASS’,”);
    define (‘DBNAME’,’codeigniter’);
    //$user_name = trim($this->session->userdata(‘username’));

    global $dbh;
    $dbh = mysql_connect(DBPATH,DBUSER,DBPASS);

    How could do this in ms sql server.


    1. Neville says:

      Hi, I am getting the error mysql deprecated function…how to resolve this…is it not possible to use codeigniter functions for db selections??

      Please do contact me at for any advice..

      1. yoga kumboro says:

        can I see the detail what you need ?

  25. sb says:

    I have given my email id, but i could not download. As it leads to some ad pages. please help to download.Thanks

    1. Download link is sent to your email address.
      Download link –


      1. HEMAL says:


        1. HEMAL says:

          Not Found

          The requested URL /CodeIgniter/index.php/users was not found on this server.

          1. andi says:

            Check in welcome.php in line 99

        2. You couldn’t download the source files?
          After installed showing error? It’s in localhost or live web server? Did you configured correctly?

          1. hemal says:

            its in localhost …….

          2. Check the rewrite_module is enable in apache.
            click: WAMP icon->Apache->Apache modules->chose rewrite_module

  26. yoga kumboro says:

    Dear Sumith Harshan

    I’ve read your article about facebook/gmail like chat.
    And I implemented succesfully on my localhost with original version of yours.
    But when I tried to modify your code to be my version, I seems so tricky.
    I got problem to access view from url inside Jquery chat.js.

    here’s some of mycode inside chat.js jquery :

    url: “http://localhost/system/application/views/reminder/chat.php?action=chatheartbeat”,
    cache: false,
    dataType: “json”,
    success: function(data) {

    I’ve debug this problem using firebugs, and try so many way including change :

    url: “http://localhost/system/application/views/reminder/chat.php?


    – url: “../system/application/views/reminder/chat.php?
    – url: “/chat.php?

    but still I didn’t succeed

    Please help, coz I’m getting crazy about this

  27. sandeep says:

    Hi there,,
    i have download copied and run your code but it didnt work….chat box appears when clicked to the username(CI_users) bt when msg is typed and clicked,msg dissapears and database has no messages saved..

  28. hello sumith , i try to install source code in my local, but message cannot received to other client, can you help me ?

    1. yoga kumboro says:

      liat di chat.js nya gan, di baris 224 diganti, sesuai in sama punya agan

      1. sudah solved om salah koneksi db aja,soalnya di view chat nya ada koneksi ke db nya jga ternyata 🙂

        1. Jama Muttaqin says:

          Punyaq ttp g bisa gan, udah tak sesuaiin dengan sample. Link juga sudah sesuai folderq

  29. Umar Farooq says:

    thanks Sumith script is working but i want to store the sender and receiver id in chat table can you help me how to make it?

  30. Heer Shah says:

    sir, this is the start page of this project when i click on the user login this error occur….. plz solve it sir

  31. Heer Shah says:

    this error is occur

    1. check the model/user.php and views/user folder is exist.Also check server is enable for mod_rewrite of apache.


  32. ijaz says:

    i have a serious problem chat is open in chrome but when i tried to send chat it then it doesnt work and on sender name it appears undefiend

    1. ijaz says:

      just like this only in chrome

        1. chat.php –> add “@” mark before the mysql_query as follows.

          Hope this work and this is may be in the wamp new server.


  33. anjum says:

    sir can u kindly add video tutorial describing how to run this chat

  34. Shijin says:

    Not working,Download link will download an exe file.

    1. Read the mentioned in red color how to download the source code.It’s not a exe file.

  35. anjum says:

    sir ci_sessions table is empty, no data is being stored

  36. frank says:

    how to add group chat in this plugin

  37. sasi says:

    TypeError: jQuery.cookie is not a function any help???

    1. Hi,
      Check the jquery_cookie.js file is added to the header file/into your site.Also remember add jquery library file add top of the all js files.

      and THEN


  38. oka says:

    thanks SO Much for U’re tutorial, but I can’t find who is the users onLine or offLine

  39. siddhant says:

    its not working sumith

  40. Vijay Anand says:

    chat is excellent but i am getting problem , when chat is opened in
    different tab of same browser then not all window of chat is update
    when message recieved.

  41. van says:

    How can i download the full source code?

  42. Jama Muttaqin says:

    It was not working when i activated CSRF Protection

    1. Jama Muttaqin says:

      This my inspect element

      1. check chat.js file for correctly added url there.


  43. Alexanedeo says:

    Hi Sumith

    i want to download code but it’s not working and downloadable link not opening.


    1. Source code is emailed.


      1. Alexanedeo says:

        Thanks you…

  44. Alexanedeo says:

    Thanks 🙂

  45. Rajendra says:

    chat name not have option for define desplay name and user it, if bother user have same name then who it work

  46. Satish says:

    i integrate this chat module but i need chat icon ,How to add Chat icon??

    1. Hi,
      Chat emoticons will add into this chat module and fix bugs in future version.

  47. Vivek S Nair S says:

    Hi Sir,
    Its awesome, but response time is high. how could I fix the response time. If I entered a message in the box it will appear only after some time. and it takes more time to reach to the other user.
    Please help me to find a solution for that.

  48. Thamaraiselvam says:

    cannot download code error 404

      1. Thamaraiselvam says:

        Thank you dear and where i need to give my database configurations? i gave in chat.php should i give in database.php also?

        1. Yes, chat.php and normal setup on codeigniter db details on config or database file.

          1. Thamaraiselvam says:

            gave it even getting error like

            A Database Error Occurred

            Error Number: 1046

            No database selected

            SELECT ci_users.user_id, ci_users.user_name, ci_users.user_email,
            FROM (ci_users)
            WHERE ci_users.user_id = ‘2’
            ORDER BY ci_users.user_id asc

            Filename: C:xampphtdocschattingsystemdatabaseDB_driver.php

            Line Number: 330

          2. “No database selected” means you wrongly added database name in both files.check the db name, user name..etc twice.

          3. Thamaraiselvam says:

            it works , thank you man you are really helpful

          4. Thamaraiselvam says:

            why you have put db configuration in config file rather than in database file?
            and if i remove db config from config file and added into database file it is not working ? why?

  49. aminah says:

    hai. i am already try this code. When i execute the code but i couldn’t get the userList display. Can you help me to solve this?

    1. Hi,
      No users / empty the value of $listOfUsers in userList.php. It getting values from controller/chat.php line 22,23 as following.
      //Get all users
      $this->outputData[‘listOfUsers’] = $this->users_model->getUsers();

      So check that returning empty values.


      1. aminah says:

        thanks ! i am already solve the problem. But i met a new problem. When i click the name, the popup box did not appear. When i check the view source, it said that the page not found. Can you help me?

  50. siti says:

    hi sumith, can you explain how to change the url in chat.js? i dont understand how to do it. Anyone also can help me. please… 🙁

  51. Ahmad says:

    Excuse me brother. I got problem with the jquery file? I download it from the jquery website. Seems the jquery fils isnt working. I really need your help.

  52. nilu says:

    this demo is implement to my work so that is not proper how can dynamic this demo

  53. Abhishek says:

    i m unable to Download Full CodeIgniter Chat Example.. the link send me on my email is not open the download page gives an error ..plz help meeeee to download this full source code..

    1. Full source code is here.

      Let me know if not worked.


  54. anas rock says:

    thank you for job !
    but i have many problems , and i want to help me plz 🙁 🙁 🙁 !
    first problem :
    when i login tow user ann and smith
    send message from smith to ann nothing disable in ann similar this images !
    twice problem :
    the name of Ann id disable as “undefined”
    pleas help me 🙂 !
    thanks alooooooooooooooooooooooooo0o0o0o0o0o0T !

  55. Guest says:

    json file is missing

  56. Parthan Hugelview says:

    i can’t see the chat message, is there any json file

  57. thais says:

    The download link isn’t working anymore..

    1. thais says:

      Do you still have the files? 🙂

  58. rahul kumar says:

    chat.php file is in core php therefor , is it need to change in CI???

    1. Hello Rahul,
      You can see chat.php file in the controller.

      That not need to change. But according to your view files, that may be you have to change.
      Example:- $this->load->view(‘chat/userList’,$this->outputData);

      My folder structure is views/chat/userList.php


      1. rahul kumar says:

        Thanks for your fast reply, but i am talking about view/chat/chat.php file. so please help me on this, all queries in core php here therefore its not working to create session plz help me.

        1. Chat.php controller. change there view name:-

          to:- $this->load->view(‘chat/chat’,$this->outputData);

          Note there this->load->view(‘viewfoldername/filename’,$this->outputData);

          1. rahul kumar says:

            now its showing this error when i chaged it to chat/chat

            A PHP Error was encountered

            Severity: Notice

            Message: Undefined index: action

            Filename: chat/chat.php

            Line Number: 34

      2. rahul kumar says:

        sir i did’t using here userList in my project i just want to know how to
        use codeigniter session username in view/chat/chat.php . In db from
        field is going blank because of that please help me.

  59. Ketan Sangani says:

    Your Code Works Fine..But if i logged out after 2 hours as set $config[‘sess_expiration’] = 7200;
    but still i appeared online..plzz help to solve this??

  60. Himasha Liyanage says:

    hi sir i implemented your code and it doesnt show any online users.
    it just shows the column names.please help

    1. hi,
      It’s in localhost or in the web server as live?
      Check the config file if correct,views/chat/chat.php for config details and chat controller.

      Check the email for info. I’ll send more details 2mrw.

      1. Himasha Liyanage says:

        still nothing changed!!thank you for past reply

        1. Read these instructions carefully and double check the code.

          1-Check the controller/chat.php
          There you can see it’s fetching list of users from the model.
          Line 22,23

          //Get all users
          $this->outputData[‘listOfUsers’] = $this->users_model->getUsers();

          So check it’s >getUsers function in the models/users_model.php

          Make sure your users table name,column names are correctly placed there.
          If you did it correctly this function is returning the list of users.

          2-You can see the correct view is $this->load->view(‘chat/userList’,$this->outputData);

          You will see i got the lst of users from chat.php controller as following.

          foreach($listOfUsers->result() as $res)

          …….. etc.

          So in this loop is showing list of users.

          check there you added correct db details.

          check your file path there:-
          Line 224.
          url: “http://localhost/CodeIgniter/application/views/chat/chat.php?action=chatheartbeat”,

          Line 285

          Line 352

          Line 387
          url: “http://localhost/CodeIgniter/application/views/chat/chat.php?action=startchatsession”,

          Let me know if you have further questions.

          Thank you