How To Build Web Application CRUD with Codeigniter 3.1.0

How To Build Web Application Login with Codeigniter 3.1.0

This tutorial is about How To Build Web Application Login with Codeigniter 3.1.0


This tutorial will guide developers in creating a simple web application authentication/login in Mesosfer using codeigniter 3.1.0. Mesosfer authentication use oAuth2.0 so you will get a token that use for authorization when operating data. This is a second section from web application tutorial series with codeigniter. If you wanna follow from the begining, you can read the first section here.


To follow this tutorial, you will need to prepare item below :

  • Sign up for an account in mesosfer cloud platform then create application and get applicationId
  • Download source framework codeigniter version 3.1.0 from this site.
  • Installed guzzle on folder vendor.

Let’s Write The Code!

Based on previous tutorial, you have User.php in folder controller. Then you just need several method to handle login process. Firstly, add method login for handling navigation to login page.

Then add view login.php in view/pages.

If you access it from browser, It will look like the picture below.


Then you can create sign in method that handle action from login.

If login success, you will get token response as authorization header that is able to help you operate or manage data.

When you’ve unauthorized, wrong password, or don’t have account, you will got error response like this :

Working with Session

In the next section (CRUD) you will need  access token for every single api execution. After login success you will get access token, to keep that you need store at session variable.

First, edit file autoload in application/config/autoload.php then add session to $autoload libraries.

Then add store session when login status success.

Create controller Animal.php to handle redirect after login for this section and page to destroy the session. In the next section you will also use this controller to manage data (CRUD).

Create view animal.php in application/views/

Add validation session in login method then redirect to page animal, if you still have session.

Add method signout to destroy all session.

Add script to show error message in login page.

So if user input wrong username or password, it will show error message like picture below :


Let’s try and share to your community. Download complete code here.


With mesosfer you don’t need to setup authentication library, just create apps and call RestAPI that provided. So easy and simplify to implement. With authorization token your data will keep secure and safe. Always follow tutorial for upgrade information and knowledge from mesosfer.

Mesosfer helps you connect your project to the cloud. Cut off the development process so you can straight into the delivery process instead stumble on the complicated infrastructure.


  • Sjarif

    November 18, 2016

    I think :
    ‘access_token’ => $auth->access_token
    it’s wrong.

    It should be:
    ‘access_token’ => $auth->accessToken

    • Girly Saputri

      November 21, 2016

      Thanks for the correction!
      We already fixed that.


Leave a Reply