For developers

How to Add Real-Time Messaging On A Codeigniter App in Under 5 Minutes!

Codeigniter is an Application Development Framework — a toolkit — for people who build websites using PHP. Its goal is to enable you to create full-featured web applications much faster than you could if you were writing code from scratch! It offers a simple interface and a logical structure.

Team CometChat • Apr 21, 2020

Codeigniter is an Application Development Framework — a toolkit — for people who build websites using PHP.

Its goal is to enable you to create full-featured web applications much faster than you could if you were writing code from scratch! It offers a simple interface and a logical structure.

Basically, Codeigniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Because of its simplicity, security, and flexibility, Codeigniter makes for an awesome integration platform for any website.

It has easy templating and plugins for most of the templating engines. Codeigniter is fast, reliable, lightweight and more capable. Most importantly… it allows for the integration of real-time communication!

Websites Built Using Codeigniter!

Let’s look at a few websites that have been built using Codeigniter, to understand their widespread applications amongst different industries, as well as what they use chat for!

9gag

9gag is one of the leading players in the social media community and entertainment sector. It allows users to upload and share ‘user-generated content’ and content from other sites.

Their users started requesting for a way to connect with each other to stay updated, as a result, 9Chat was born.

9Chat is also one of the largest International Forum, Groups & Communities by 9gag. Users can indulge in discussions, explore their areas of interest and share their stories. It is a great platform for users to engage with each other.

Chat lets the users connect in real time via chat

99 Acres

99 Acres is India’s leading portal for property where users can buy, sell or rent real estate in any part of the country.

It enables buyers on the lookout for a property to shortlist inventory sitting in their comfort zones, avoiding the hassles of visiting each site in person.

Similarly, sellers have a better chance of disposing of their properties because of the vast number of buyers shopping on 99 Acres for their suitable home.

Plus their chat functionality helps buyers and sellers connect with each other to take the discussions further by sharing pictures, videos, documents and so on. They can exchange numbers and even negotiate on the prices, which means better conversion rate.

99 Acres has established itself as a leading player in the real estate industry. The success can be attributed to the ease of communication provided to the buyers and sellers, which leads to a faster decision making. Not just that, they have a hundred different user forum categories, Q&A discussion sessions and much more.

99acres has multiple forums & discussion rooms to connect people better.

Both the above websites are successful because they realized the need for the integration of real-time communications’ technology on their platforms.

People want the answers now, at the moment and that is only possible when web applications are built keeping the basic need of humans at the forefront — Communication!

What did the above successful websites have in common?

The one common factor amongst the above-mentioned websites is their real-time chat feature, which is a great tool for not only solving customer queries without delay but also building engagement as it lets more people communicate with your website.

They don’t have to strike off a particular time or get on a call or email a business separately – they are available at the click of a button.

Real-time communication is a means of sharing information and interacting with people through network connections just as if they were face-to-face.

Real-time communication applications and solutions can be used in virtually every industry: financial services, healthcare, legal firms, education, retail, etc. can all benefit and improve services.

In a website, there is a huge importance attached to real-time communication. It is crucial in today’s time to ensure that a website’s communication technology meets the heightened demands of today’s consumers.

Some real-time features that are a must for every website today are:

  • One on one messaging: To enable a user to communicate privately with another, without the fear of intrusion!

  • Group messaging: To help users build same-interest groups and communicate to a wider audience, with the added facility of making it ‘open for all’ or ‘admission by invitation only’!

  • File sharing: To help users share files and images on the go, and on time!

  • Video calling/voice calling conference: Engage in a high-quality Video call or voice call, without being present under the same roof and not compromising on personal schedules.

  • Real-time messaging: Text each other on the fly, letting tasks flow smoothly without coming to a standstill.

An interactive website that solves customer queries with the help of real-time solid communication features, highlights a positive image of the business.

How Do You Get These Features On Any Website?

If you are looking to integrate these real-time chat functionalities on your website, you typically have two options:

Build a Codeigniter real-time chat from scratch! However, building a chat application using Codeigniter framework is not really simple.

It involves a lot of code — you have to create multiple controllers, especially in the case of larger projects, to increase readability and maintainability.

You also need a database and a suitable, sustainable model. For the user interface, you need to get the basic HTML framework in place using jQuery and Bootstrap.

This type of chat integration generates numerous server requests, and therefore a relatively high server load for the database. Not to mention the costs of developers and maintaining it!

There’s another simpler, more sustainable options — that won’t drain any of your resources!

Integrate Real-Time Communication Using CometChat!

CometChat integrates with Codeigniter within minutes! CometChat can be easily embedded in any page of your website.

The users can use a host of the features like real-time text chat, voice and video calling, file sharing, video broadcasting and much more.

Unlike the above option to build the chat option from scratch, where there is little flexibility, CometChat allows for customization with respect to different themes and nine different languages for your app/website. Some other incredible features your users get access to are:

  • They don’t need to log in separately into CometChat — they are automatically logged into it when they log onto your website!

  • CometChat offers automatic synchronization of all your online users.

  • Users can access other user profiles and their avatars easily.

  • Website owners can monetize them using CometChat features such as role based access control, credit deduction, and advertisements on chat, and generate additional revenue.

Here’s How You Can Integrate CometChat With Codeigniter!

It only takes a few minutes to install CometChat on your CodeIgniter website. Once installed, you can access CometChat via our Admin Panel.

Prerequisites

1. Signup for a free trial

First select a plan from the CometChat free trialpage, enter your email address and start your free trial for 7 days.

2. Note your API Keys

Sign in to your CometChat Client Area and click on the Manage button and then note down the keys present in API Keys (top right button) section- API Key, License Key, and App ID. You may need these during installation.

Install CometChat

CometChat comes with 2 different layouts you can choose from.

Docked Layout

The docked layout creates a popup floating chat widget which is placed at the bottom left or right corner of your website.

Paste the following code right before the closing tag of every page where you want CometChat to appear. Ideally, you can add this code to your footer template.

Modify the highlighted code to match the variables you’ve used. (We’ve populated it with the most common values.)

<code class="language-markup">
<script>
var chat_appid = 'APP_ID';
</script>
session->userdata('id') && $this->session->userdata('id') > 0) { ?>
<script>
var chat_id = "<?php echo $this->session->userdata('id'); ?>";
var chat_name = "<?php echo $this->session->userdata('name'); ?>";
var chat_link = "<?php echo $this->session->userdata('link'); ?>"; //Similarly populate it from session for user's profile link if exists
var chat_avatar = "<?php echo $this->session->userdata('avatar'); ?>"; //Similarly populate it from session for user's avatar src if exists
var chat_role = "<?php echo $this->session->userdata('role'); ?>"; //Similarly populate it from session for user's role if exists
var chat_friends = '<?php echo $this->session->userdata('friends'); ?>'; //Similarly populate it with user's friends' site user id's eg: 14,16,20,31
</script>

<script>
(function() {
var chat_css = document.createElement('link'); chat_css.rel = 'stylesheet'; chat_css.type = 'text/css'; chat_css.href = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.css';
document.getElementsByTagName("head")[0].appendChild(chat_css);
var chat_js = document.createElement('script'); chat_js.type = 'text/javascript'; chat_js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.js'; var chat_script = document.getElementsByTagName('script')[0]; chat_script.parentNode.insertBefore(chat_js, chat_script);
})();
</script>

Embedded Layout

The Embedded Layout creates and embeds a chat widget on any page of your website.

Paste the following code wherever you wish to embed CometChat on your website.

Modify the highlighted code to match the variables you’ve used. (We’ve populated it with the most common values.)

<code class="language-markup">
<script>
var chat_appid = 'APP_ID';
</script>
session->userdata('id') && $this->session->userdata('id') > 0) { ?>
<script>
var chat_id = "<?php echo $this->session->userdata('id'); ?>";
var chat_name = "<?php echo $this->session->userdata('name'); ?>";
var chat_link = "<?php echo $this->session->userdata('link'); ?>"; //Similarly populate it from session for user's profile link if exists
var chat_avatar = "<?php echo $this->session->userdata('avatar'); ?>"; //Similarly populate it from session for user's avatar src if exists
var chat_role = "<?php echo $this->session->userdata('role'); ?>"; //Similarly populate it from session for user's role if exists
var chat_friends = '<?php echo $this->session->userdata('friends'); ?>'; //Similarly populate it with user's friends' site user id's eg: 14,16,20,31
</script>

<script>
var chat_height = '600px';
var chat_width = '990px';

document.write('<div id="cometchat_embed_synergy_container" style="width:'+chat_width+';height:'+chat_height+';max-width:100%;border:1px solid #CCCCCC;border-radius:5px;overflow:hidden;"></div>');

var chat_js = document.createElement('script'); chat_js.type = 'text/javascript'; chat_js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchatx_xcorex_xembedcode.js';

chat_js.onload = function() {
var chat_iframe = {};chat_iframe.module="synergy";chat_iframe.style="min-height:"+chat_height+";min-width:"+chat_width+";";chat_iframe.width=chat_width.replace('px','');chat_iframe.height=chat_height.replace('px','');chat_iframe.src='https://'+chat_appid+'.cometondemand.net/cometchat_embedded.php'; if(typeof(addEmbedIframe)=="function"){addEmbedIframe(chat_iframe);}
}

var chat_script = document.getElementsByTagName('script')[0]; chat_script.parentNode.insertBefore(chat_js, chat_script);
</script>

There… as simple as that! Don’t waste any time building a chat for your website built using Codeigniter! Codeigniter chat integration just got easier — thanks to CometChat!

Team CometChat

We build chat and messaging SDKs that let you quickly code a full-featured chat experience into any mobile or web app.

Try out CometChat in action

Experience CometChat's messaging with this interactive demo built with CometChat's UI kits and SDKs.