Gmail/Facebook like Chat With CodeIgniter
Hey to all my CodeIgniter friends. SO you all have been waiting for a Gmail and Facebook like chat to be implemented in Codeigniter. Well this is an extended version of
this chat.
Download the files from the link above and do the following things.
Before doing the setup below. Please configure your database settings first.
The fact is that you need to to change the chat.js file
var baseUrl = "http://yourURl.com/chatfolder"; // or your ip address incase you are using over intranet.
Change all your URls in th script from
url: "chat.php?action=chatheartbeat",
to
url: baseUrl+"chat.php?action=chatheartbeat",
open samplea.php
<?php session_start(); $me = $_GET['me']; $you= $_GET['u']; $_SESSION['username'] = $me; // Must be already set ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <title>Sample Chat Application</title> <style> body { background-color: #eeeeee; padding:0; margin:0 auto; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size:11px; } </style> <link type="text/css" rel="stylesheet" media="all" href="css/chat.css" /> <link type="text/css" rel="stylesheet" media="all" href="css/screen.css" /> <!--[if lte IE 7]> <link type="text/css" rel="stylesheet" media="all" href="css/screen_ie.css" /> <![endif]--> </head> <body> <div id="main_container"> <a href="javascript:void(0)" onclick="javascript:chatWith('<?=$you?>')">Chat With <?=$you?></a> <a href="javascript:void(0)" onclick="javascript:chatWith('babydoe')">Chat With Baby Doe</a> <!-- YOUR BODY HERE --> </div> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/chat.js"></script> </body> </html>
Copy the code to your CodeIgniter View and make necessary changes like <?=base_url()?> inclusion and other stuff.
At the top of the file you see the following code
<?php session_start(); $me = $_GET['me']; $you= $_GET['u']; $_SESSION['username'] = $me; // Must be already set ?>
To change that code to Codeigniter do the following steps.
In your controller (the one that calls your view), either use session or pass names as parameters.
<?php function chat($me, $you) { $data['me'] = $me; $data['you'] = $you; $this->load->view('chat', $data); } ?>
I use two parameters because one is for your name and other is the name for the person you want to chat with.
Make sure names should not have any spaces or dotz. It should be just words or underscores.
ok so.
change the following code
<a href="javascript:void(0)" onclick="javascript:chatWith('babydoe')">Chat With Baby Doe</a>
to this
<a href="javascript:void(0)" onclick="javascript:chatWith('<?=$you?>')">Chat With <?=$you?></a> //---make it dynamic.
Open two of your browser and open the link. be sure either using localhost or the ip address. depending on what you have used in your chat.js
In Firefox open this link http://localhost/gchat/welcome/chat/misha/rahul and in the other browser open this
http://localhost/gchat/welcome/chat/rahul/chat. Click the first link.
Then you should have your chat working fine.
Tags: chat, codeigniter, JQuery, Php

hmmmmm. where is demo…………?
great dude..
ek din tum bhi bharat ka naam jarur roshan karoge..
Oops No demo. Its hard to put all in COdeigniter…
Very interesting article, thanks. Keep up the good work.
hey boss u should give thank to http://anantgarg.com/2009/05/13/gmail-facebook-style-jquery-chat/
Hey gaurav i agree. Thats why i gave link to the real link. I would have given a whole new chat.
Thank you very much for sharing this. I have subscribed to your RSS feed. Please keep up the good work.
hi i implemented it but when i type something and click enter it says me undefined : hi
what is the issue ?
check your variables and session variables
in one of the browser open sample.php?me=your_name&u=user_name
in the other browser use sample.php?me=user_name&u=your_name
This will do.