Codeigniter + Ion Auth part 1

In this episode we will learn about setting the CodeIgniter framework to work with sessions and importing the necessary files of the Ion Auth library and create the login form.

Setting up CodeIgniter to work with sessions

Just to make sure everything is OK, we will start by having a fresh install of CodeIgniter. We will install it directly inside the htdocs or www (assuming you have XAMMP installed or some other kind of wamp or lamp stack installed). This way we can access the site by typing : “http://localhost/” in our browser. If you already installed sessions correctly, you can skip this step.

We will use the database driver for keeping the session data. In order to do this we will go to our config file (application/config/config.php) and look for the following lines (more or less…):

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Now, let’s go to our autoload.php (application/config/autoload.php) and autoload the session library. Look for the line:

$autoload['libraries'] = array();
$autoload['libraries'] = array('session');
$autoload['helper'] = array('url');

The one above is an sql command. You can simply copy it and paste it using PHPMyAdmin’s interface. I sure hope you know how to create a table in MySQL…

CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
);

Installing Ion Auth

In order to install Ion Auth we first need to… download it. We do this from it’s Github repository: https://github.com/benedmunds/CodeIgniter-Ion-Auth.

Once we’ve downloaded it, we only need to copy/paste some files:

config/ion_auth.php

We need to put this file inside our application/config directory.

language/english/ion_auth_lang.php

We need to put this in our application/language/english directory. If you’ve set another language for your application inside the config.php file, you should copy that language in the appropriate language directory.

libraries/Ion_auth.php and libraries/Bcrypt.php

We should copy these too, inside application/libraries directory.

models/ion_auth_model.php

Copy this file inside the application/models directory. Make sure you copy it by renaming the file so that it starts with upper-case letter: Ion_auth_model.php

Once we did all the copy/pasting we need to set up the tables needed for Ion Auth to work. In order to do this look for a directory named “sql” inside the library’s zip archive. In there we will find an sql command for creating the tables necessary for the library: ion_auth.sql.

Configuring the Ion Auth library

Now that we’ve imported the files and created the tables, we need to configure the library. To do this, we go to our application/config/ion_auth.php.

What should we change here?

We can change $config[‘site_title’], the $config[‘admin_email’] (preferably with a valid email).

Now the important parts.

0 0 votes
Article Rating

by kushan


Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments