This section will show you how to properly install the CodeIgniter framework and the Tank Auth library, then configure both for use with our simple blog. By the end of this part you should have a working simple user login system.
I’m going to start with a clean installation of CodeIgniter downloaded straight from EllisLab’s site, but if you’re not familiar with the framework also look here for more thorough installation directions:
I’m going to copy the folder included in the zip (CodeIgniter_2.1.3) into my
/var/www/ directory (the root directory for websites on my machine) and rename it
myblog. Now this is my current file structure (you can delete the included user_guide) :
Note : I would usually move my /application and /system folders a directory above my web root, this is added security to ensure nobody can directly access these files from a browser. For this simple tutorial I’m going to leave it up to the basic .htaccess files included in every CI folder by default to keep people out and NOT let this site go live as is. If I was to move the folders however, at this point I would have to update the variables
$application_folder values in the main index.php file located in the website’s folder with the correct file paths.
Install Tank Auth
Next a fresh installation of Tank Auth is needed. Download page:
After extracting Tank Auth merge it’s
application folder with
/var/www/myblog/application/ (your site’s
/application directory). Move the captcha folder to the root of your website as well, see changed folder structure below :
/var/www/myblog/captcha/ (this folder is now merged with Tank Auth’s application folder)
From this point on I won’t be typing out my entire specific folder directory. I will be shortening any references to folder directory to something like this:
CodeIgniter Sessions Configuration
In order to use sessions in our blog we will need to set up an encryption key; go to randomkeygen.com and copy one of the ‘CodeIgniter Encryption Keys’ on the page.
In your site directory find and open this file, then edit the following lines:
$config['encryption_key'] = '' <= Paste encryption key between the ”
$config['sess_use_database'] <= Set to TRUE
We set the above to true because in order to handle session data CodeIgniter will need a database. Create a database using whatever method you’re comfortable with (phpmyadmin,terminal), I’m naming my mysql database:
Now back to the included Tank Auth file:
schema.sql. Insert the correct tables from the .sql into your database by using phpmyadmin or by logging into mysql through your terminal.
Create ‘posts’ Table For Storing Posts
Add one more table to the database to store our posts, again, this is assuming you are familiar with creating tables in mysql:
- Name your table ‘posts’
- Include the following fields:
- ‘id’ (INT, make the primary auto-incrementing key)
- ‘title’ (VARCHAR, I put 100 chars max)
- ‘summary’ (TEXT)
- ‘content’ (TEXT)
Once you have the database tables set up let’s tell CodeIgniter where to find them :
Open the database config file located at :
This file should look a little self explanatory, fill out the lines below with your own database info and save.
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'myblog';
Config Tank Auth
The final config changes I will be making are in the Tank Auth configuration itself, open :
Now find the following lines and make sure they are both set to
$config['captcha_registration'] = FALSE;
$config['email_activation'] = FALSE;
We are removing the need to write out a captcha when registering, and disabling activation by email just to keep things simple for now.
If you navigate to your site a login form that looks like this should be visible:
Registration should be possible and a successful login will lead you to a plain page welcoming you by your entered username.
In the next part of this tutorial a home page for the blog will be created, and it will display a list of blog post titles and summaries. In addition to an index page, we will need to create a page for users to view a complete single post.