CodeIgniter Tutorial – Register and Login with Ajax

Codeigniter is a PHP framework that contains libraries, helpers, plugin-in, and other resources. It will make the PHP codes simple, quick, and user-friendly. It is a lightweight MVC programming technique to keep the business logic separate from the layout of the application. MVC stands for Model View Controller which is a software development method splitting the data layer (Model), the business logic (Controller), and the layout of the application (View). With the help of this framework, we will be building the simple Register and Login application with Ajax.

Table of Content

  1. Introduction
  2. Configure Config File
  3. Configure Database
  4. Database Connection
  5. Register and Login Demonstration
  6. Source Code

Introduction

This tutorial will teach you to create a register and login system with Ajax. The registration and login system is the most important role in the web application. The user’s login status will be checked by the session.

The source code of this application is provided at the end of this tutorial, you can easily download them by clicking on the download button. As well as the database is also required to run the application correctly. So please do not forget to download the database and run them into the phpMyAdmin.

Configure Config File

In this part, Go to the config.php file i.e. application/config/config.php and you must change the base URL root to work the code properly without any errors. You will have to modify the base URL value in the config file to help the CodeIgniter to guess the protocol and path of your installation.


<?php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
| http://localhost/codeigniter_register_login/
*/
$config['base_url'] = 'http://localhost:9080/codeigniter_register_login/';

?>

Configure Database

Database Name: codeigniter_register_login
Table Name: users
Table Column: id, username, password, salt, name, contact

To create the database for this tutorial, either you can download the SQL file which is provided at the end of this tutorial or copy and paste the following SQL command into your MYSQL Database.


CREATE DATABASE `crud_datatables_codeigniter`;

CREATE TABLE `codeigniter_register_login`.`users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `salt` text NOT NULL,
  `name` varchar(255) NOT NULL,
  `contact` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Database Connection

In database.php file i.e. [application/config/database.php], contains a database connection. If you have a different database name then change the database name in the database.php file highlighted below.


$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root',
	'password' => '',
	'database' => 'codeigniter_register_login',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

Source Code !!

Download

Related Posts:

6 comments

  1. this is wonderful and nice tutorial thanks a lot for your effort

  2. Nice one, Thx

  3. pleas help ma
    which web hosting is best for me pleas guide me..

  4. How we can set base url
    In local host

  5. hi this is very helpful and good for undrestan