Step 6 – Verify CodeIgniter configuration. Is everything OK?

(created at: December 3, 2014; last update: December 7, 2015)

We’ve installed CodeIgniter framework in 5 steps (or less, depends on how you count…). Now everything should be OK.

But is it? To see if everything is OK with your fresh installation of CodeIgniter, you would have to look in a lot of files. So why not make a controller that can take a look in various location and present you the status of your CodeIgniter installation? It’s like a phpinfo() of your CodeIgniter

Let’s do it. For those who are too busy or too scared to copy/paste long parts of code, I’ve made a zip archive with the files so that you can only look at the important parts in here and then just put the files where they belong. Also, if you have some proposals to change the files, you can find them on Github (https://github.com/avenirer/CI-configuration-verifier).

We create a file named Verify.php inside application/controllers, and write the following lines:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Verify extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();

First of all we need to make sure we are in a development environment or at least that this controller can be seen only by your IP address (you’ll have to replace XXX.XXX.XXX with your IP address, of course):

    // first of all we need to make sure we are in a development environment or at least that this controller can be seen only by your IP address (you'll have to replace XXX.XXX.XXX with your IP address, of course)
    if(ENVIRONMENT!=='development' || $_SERVER['REMOTE_ADDR']!=='XXX.XXX.XXX')
    {
      $this->load->helper('url');
      redirect('/');
    }
  }

Now that we’ve finished the constructor, let’s move on to our main method, the index(). We will start by getting the environment of our CI app:

  public function index()
  {
    // we should retrieve the environment we are into
    $data['environment'] = ENVIRONMENT;

The next thing we do is to see what classes, helpers and models are loaded by default. For this we can use some of the Loader.php properties. Being protected, the properties cannot be accessed directly, so we will need to make some getters in a MY_Loader.php. After we’ve done the Controller we will create a MY_Loader.php. Now let’s see what important info can we retrieve from the Loader.php:

    // we need to see what classes are loaded by default. get_loaded_classes() is not a native Loader method, but a method from MY_Loader. It retrieves the list of classes that are loaded (which in Loader.php is actually protected)
    $data['loaded_classes'] = $this->load->get_loaded_classes();
    // same as before, a method from MY_Loader that retrieves helpers
    $data['loaded_helpers'] = $this->load->get_loaded_helpers();
    // same as before, a method from MY_Loader that retrieves the models loaded
    $data['loaded_models'] = $this->load->get_loaded_models();

Now we will retrieve everything that can be found inside the config.php file:

    // also retrieve the config data
    $data['config'] = $this->config->config;

After that, let’s turn to our database. First of all, do we have a database connection established by default (with autoload – which I don’t recommend and you will see why in a next step)? If we do have the connection established let’s see what are the parameters of the connection:

    // now we will see if a connection to the database is established already (ie: if is "autoloaded"). We start by creating the message for not loaded.
    $data['loaded_database'] = 'Database is not loaded';
    // if we find that the connection is established...
    if (isset($this->db) && $this->db->conn_id !== FALSE) {
      // ...we will modify the message
      $data['loaded_database'] = 'Database is loaded and connected';
      // ...and retrieve the database settings
      $data['db_settings'] = array(
        'dsn' => $this->db->dsn,
        'hostname' => $this->db->hostname,
        'port' => $this->db->port,
        'username' => '***',
        'password' => '***',
        'database' => '***',
        // if you are sure that only the right eyes will see the controller, you can uncomment the three lines below
        //'username' => $this->db->username,
        //'password' => $this->db->password,
        //'database' => $this->db->database,
        'driver' => $this->db->dbdriver,
        'dbprefix' => $this->db->dbprefix,
        'pconnect' => $this->db->pconnect,
        'db_debug' => $this->db->db_debug,
        'cache_on' => $this->db->cache_on,
        'cachedir' => $this->db->cachedir,
        'char_set' => $this->db->char_set,
        'dbcollat' => $this->db->dbcollat,
        'swap_pre' => $this->db->swap_pre,
        'autoinit' => $this->db->autoinit,
        'encrypt' => $this->db->encrypt,
        'compress' => $this->db->compress,
        'stricton' => $this->db->stricton,
        'failover' => $this->db->failover,
        'save_queries' => $this->db->save_queries
      );
    }

Now we should verify that the directories that should be writable by our Framework are indeed writable:

    // look for the cache path
    $cache_path = ($this->config->item('cache_path') === '') ? APPPATH.'cache/' : $this->config->item('cache_path');
    // and verify that it is writable
    if(is_really_writable($cache_path))
    {
      $data['writable_cache'] = TRUE;
    }
    // also look for the logs path
    $log_path = ($this->config->item('log_path') === '') ? APPPATH.'logs/' : $this->config->item('log_path');
    // and verify if is writable
    if(is_really_writable($log_path))
    {
       $data['writable_logs'] = TRUE;
    }

Optionally, if you think you will have some directories where you or your users will upload files, you can add another check for those directories:

    // optionally you can look for other writable directories. In this case I have an uploads directory in public folder
    $this->load->helper('url');
    $uploads_path = base_url().'uploads';
    if(is_really_writable($uploads_path))
    {
      $data['writable_uploads'] = $uploads_path.' is writable';
    }
    else
    {
      $data['writable_uploads'] = '<span class="red"><strong>'.$uploads_path.'</strong> is not writable</span>';
    }

I guess we have all we need for now. It’s time to load our view so that we can show our analysis results:

    // now we load the view, passing the data to it
    $this->load->view('verify_view', $data);
  }
}
/* End of file 'Verify' */
/* Location: ./application/controllers/Verify.php */

As you can see at lines 19 to 24 we used some methods that are not native to the framework. Being loader methods, we must write a MY_Loader.php file inside application/core that extends the Loader controller. So let’s create the file and write the following lines:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Loader extends CI_Loader {
    function __construct() {
        parent::__construct();
    }

    public function get_loaded_classes()
    {
        return $this->_ci_classes;
    }
    public function get_loaded_helpers()
    {
        $loaded_helpers = array();
        if(sizeof($this->_ci_helpers)!== 0) {
            foreach ($this->_ci_helpers as $key => $value)
            {
                $loaded_helpers[] = $key;
            }
        }
        return $loaded_helpers;
    }
    public function get_loaded_models()
    {
        return $this->_ci_models;
    }
}
/* End of file 'MY_Loader' */
/* Location: ./application/core/MY_Loader.php */

Now, all we have to do is write the view that will display the data. So, create verify_view.php inside application/views with the following lines:

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Verify my Codeigniter Framework</title>
    <style>
        /* a small css reset */
        html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;}
        article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {display: block;}
        body {line-height: 1;}
        /* and some styling */
        strong {font-weight:bold;}
        body {font-family: "Arial", Helvetica, Arial, sans-serif;font-size: 14px;background-color: #fefedc;color: #1f191d;}
        ul {list-style: none;}
        h1 {font-size: 24px;font-weight: bold;text-align: center;line-height: 48px;}
        table {border-collapse: collapse; border-spacing: 0;width: 820px;}
        table, th, td {border: 1px solid #3a6fb7;background-color: #caebfc;margin: 10px auto;}
        th, td {padding: 5px;vertical-align: middle;}
        th {text-align: right;background-color: #3a6fb7;color: #fefedc;}
        thead th {background-color: #ff3f7b;font-size: 18px;font-weight: bold;color: #fefedc;text-align: center;}
        .center {text-align: center;}
        .red {color: #ff3f7b;}
    </style>
</head>
<body>
<h1>My Codeigniter Framework:</h1>
<table>
    <thead>
    <tr>
        <th>Environment</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>
            <?php echo $environment; ?>
        </td>
    </tr>
    </tbody>
</table>
<table>
    <thead>
    <tr>
        <th colspan="3">Loader settings</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th class="center">Loaded classes:</th>
        <th class="center">Loaded helpers:</th>
        <th class="center">Loaded models:</th>
    </tr>
    <tr>
        <td>
            <ul>
                <?php
                foreach ($loaded_classes as $class) {
                    echo '<li>' . $class . '</li>';
                }
                ?>
            </ul>
        </td>
        <td>
            <ul>
                <?php
                foreach ($loaded_helpers as $helper) {
                    echo '<li>' . $helper . '</li>';
                }
                ?>
            </ul>
        </td>
        <td>
            <ul>
                <?php
                foreach ($loaded_models as $model) {
                    echo '<li>' . $model . '</li>';
                }
                ?>
            </ul>
        </td>
    </tr>
    </tbody>
</table>
<div style="clear:both; width: 820px; margin:auto;">
<div style="float: left;">
    <table style="width: 400px;">
        <thead>
        <tr>
            <th colspan="2">Configuration:</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>Base URL:</th>
            <td><?php echo $config['base_url']; ?></td>
        </tr>
        <tr>
            <th>Index page:</th>
            <td><?php echo $config['index_page']; ?></td>
        </tr>
        <tr>
            <th>Language:</th>
            <td><?php echo $config['language']; ?></td>
        </tr>
        <tr>
            <th>Charset:</th>
            <td><?php echo $config['charset']; ?></td>
        </tr>
        <tr>
            <th>Enable Hooks:</th>
            <td><?php echo(($config['enable_hooks']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Subclass prefix:</th>
            <td><?php echo $config['subclass_prefix']; ?></td>
        </tr>
        <tr>
            <th>Composer autoload:</th>
            <td><?php echo(($config['composer_autoload']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Permited URI chars:</th>
            <td><?php echo $config['permitted_uri_chars']; ?></td>
        </tr>
        <tr>
            <th>Allow GET array:</th>
            <td><?php echo(($config['allow_get_array']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Enable query strings:</th>
            <td><?php echo(($config['enable_query_strings']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Controller trigger:</th>
            <td><?php echo $config['controller_trigger']; ?></td>
        </tr>
        <tr>
            <th>Function trigger:</th>
            <td><?php echo $config['function_trigger']; ?></td>
        </tr>
        <tr>
            <th>Directory trigger:</th>
            <td><?php echo $config['directory_trigger']; ?></td>
        </tr>
        <tr>
            <th>Log threshold:</th>
            <td><?php echo $config['log_threshold']; ?></td>
        </tr>
        <tr>
            <th>Log path:</th>
            <td><?php echo(($config['log_path']) ? $config['log_path'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Log file extension:</th>
            <td><?php echo(($config['log_file_extension']) ? $config['log_file_extension'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Log file permissions:</th>
            <td><?php echo $config['log_file_permissions']; ?></td>
        </tr>
        <tr>
            <th>Log date format:</th>
            <td><?php echo $config['log_date_format']; ?></td>
        </tr>
        <tr>
            <th>Error views path:</th>
            <td><?php echo(($config['error_views_path']) ? $config['error_views_path'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Cache path:</th>
            <td><?php echo(($config['error_views_path']) ? $config['cache_path'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Standardize new lines:</th>
            <td><?php echo(($config['standardize_newlines']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Compress output:</th>
            <td><?php echo(($config['compress_output']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Time reference:</th>
            <td><?php echo $config['time_reference']; ?></td>
        </tr>
        <tr>
            <th>Rewrite short tags:</th>
            <td><?php echo $config['rewrite_short_tags'] ? 'TRUE' : '<span class="red">FALSE</span>'; ?></td>
        </tr>
        <tr>
            <th>Reverse Proxy IPs:</th>
            <td><?php echo $config['proxy_ips']; ?></td>
        </tr>
        </tbody>
    </table>
    
</div>
<div style="float: right; width: 400px;">
    <table style="width: 100%;">
        <thead>
        <tr>
            <th>Writable directories</th>
        </tr>
        </thead>
        <tbody>
        <?php
        echo ($writable_cache) ? '<tr><td>The cache directory is writable</td></tr>' : '<tr><td><span class="red">The cache directory is not writable</span></td></tr>';
        echo ($writable_logs) ? '<tr><td>The logs directory is writable</td></tr>' : '<tr><td><span class="red">The logs directory is not writable</span></td></tr>';
        echo '<tr><td>'.$writable_uploads.'</td></tr>';
        ?>
        </tbody>
    </table>
    <table style="width: 100%;">
        <thead>
        <tr>
            <th colspan="2">XSS:</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>Global XSS filter:</th>
            <td><?php echo(($config['global_xss_filtering']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        </tbody>
    </table>
    <table style="width: 100%;">
        <thead>
        <tr>
            <th colspan="2">CSRF protection</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>CSRF protection:</th>
            <td><?php echo(($config['csrf_protection']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>CSRF token name:</th>
            <td><?php echo $config['csrf_token_name']; ?></td>
        </tr>
        <tr>
            <th>CSRF cookie name:</th>
            <td><?php echo $config['csrf_cookie_name']; ?></td>
        </tr>
        <tr>
            <th>CSRF expire:</th>
            <td><?php echo $config['csrf_expire']; ?></td>
        </tr>
        <tr>
            <th>CSRF regenerate:</th>
            <td><?php echo(($config['csrf_regenerate']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>CSRF exclude URIs:</th>
            <td>
                <?php
                if (sizeof($config['csrf_exclude_uris']) > 0) {
                    foreach ($config['csrf_exclude_uris'] as $excluded) {
                        echo $excluded;
                    }
                }
                ?>
            </td>
        </tr>
        </tbody>
    </table>
    <table style="width: 100%;">
        <thead>
        <tr>
            <th colspan="2">Sessions and cookies</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>Encryption key:</th>
            <td><?php echo $config['encryption_key']; ?></td>
        </tr>
        <tr>
            <th>Session driver:</th>
            <td><?php echo $config['sess_driver']; ?></td>
        </tr>
        <tr>
            <th>Session cookie name:</th>
            <td><?php echo $config['sess_cookie_name']; ?></td>
        </tr>
        <tr>
            <th>Session expiration:</th>
            <td><?php echo ($config['sess_expiration']==0) ? 'Expire on close' : $config['sess_expiration']; ?></td>
        </tr>
        <tr>
            <th>Session encrypt cookie:</th>
            <td><?php echo(($config['sess_encrypt_cookie']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Match IP for sessions:</th>
            <td><?php echo(($config['sess_match_ip']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Session time to update:</th>
            <td><?php echo $config['sess_time_to_update']; ?></td>
        </tr>
        <tr>
            <th>Cookie prefix:</th>
            <td><?php echo(($config['cookie_prefix']) ? $config['cookie_prefix'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Cookie domain:</th>
            <td><?php echo(($config['cookie_domain']) ? $config['cookie_prefix'] : 'DEFAULT'); ?></td>
        </tr>
        <tr>
            <th>Cookie path:</th>
            <td><?php echo $config['cookie_path']; ?></td>
        </tr>
        <tr>
            <th>Cookie secure:</th>
            <td><?php echo(($config['cookie_secure']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        <tr>
            <th>Cookie HTTP only:</th>
            <td><?php echo(($config['cookie_httponly']) ? 'TRUE' : '<span class="red">FALSE</span>'); ?></td>
        </tr>
        </tbody>
    </table>
</div>
<div style="clear:both;">
    <table>
        <thead>
        <tr>
            <th colspan="2">Database:<br/><?php echo $loaded_database; ?></th>
        </tr>
        </thead>
        <?php
        if (!empty($db_settings)) {
            ?>
            <tbody>
            <tr>
                <th>DSN:</th>
                <td><?php echo $db_settings['dsn']; ?></td>
            </tr>
            <tr>
                <th>Hostname:</th>
                <td><?php echo $db_settings['hostname']; ?></td>
            </tr>
            <tr>
                <th>Port:</th>
                <td><?php echo $db_settings['port']; ?></td>
            </tr>
            <tr>
                <th>Username:</th>
                <td><?php echo $db_settings['username']; ?></td>
            </tr>
            <tr>
                <th>Password:</th>
                <td><?php echo $db_settings['password']; ?></td>
            </tr>
            <tr>
                <th>Database:</th>
                <td><?php echo $db_settings['database']; ?></td>
            </tr>
            <tr>
                <th>DB Driver:</th>
                <td><?php echo $db_settings['driver']; ?></td>
            </tr>
            <tr>
                <th>DB Prefix:</th>
                <td><?php echo $db_settings['dbprefix']; ?></td>
            </tr>
            <tr>
                <th>P Connect:</th>
                <td><?php echo $db_settings['pconnect']; ?></td>
            </tr>
            <tr>
                <th>DB Debug:</th>
                <td><?php echo $db_settings['db_debug']; ?></td>
            </tr>
            <tr>
                <th>Cache On:</th>
                <td><?php echo $db_settings['cache_on']; ?></td>
            </tr>
            <tr>
                <th>Cache Dir:</th>
                <td><?php echo $db_settings['cachedir']; ?></td>
            </tr>
            <tr>
                <th>Char Set:</th>
                <td><?php echo $db_settings['char_set']; ?></td>
            </tr>
            <tr>
                <th>DB Collation:</th>
                <td><?php echo $db_settings['dbcollat']; ?></td>
            </tr>
            <tr>
                <th>Swap pre:</th>
                <td><?php echo $db_settings['swap_pre']; ?></td>
            </tr>
            <tr>
                <th>Autoinit:</th>
                <td><?php echo $db_settings['autoinit']; ?></td>
            </tr>
            <tr>
                <th>Encrypt:</th>
                <td><?php echo $db_settings['encrypt']; ?></td>
            </tr>
            <tr>
                <th>Compress:</th>
                <td><?php echo $db_settings['compress']; ?></td>
            </tr>
            <tr>
                <th>Stricton:</th>
                <td><?php echo $db_settings['stricton']; ?></td>
            </tr>
            <tr>
                <th>Failover:</th>
                <td>
                    <?php
                    foreach ($db_settings['failover'] as $fail) {
                        echo $fail . '<br />';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <th>Save queries:</th>
                <td><?php echo $db_settings['save_queries']; ?></td>
            </tr>
            </tbody>
        <?php
        }
        ?>
    </table>
</div>
</div>
</body>
</html>

If everything went ok, we should call our controller from the browser. So go to http://localhost/verify and you should see something as below:

If you don’t see that, maybe something went wrong, so I’ve made a zip archive with the files for you to just copy/paste them. If it still doesn’t work, please write a comment and we will see where we both did something wrong.

21 comments

  1. Hey there!

    First thank you for the tutorial. Really helpful! The verify controller is very useful too.

    I’m just new to code igniter 3, but I’ve already created somethings with code igniter 2 in my localhost. The problem that I have is that when I run verify, in the database section, it displays “database is not loaded”. Do you know why? I’m using MAMP and my database settings are the same as the application that runs code igniter 2, which is this one:

    $active_group = ‘default’;
    $query_builder = TRUE;

    $db[‘default’] = array(
    ‘dsn’ => ”,
    ‘hostname’ => ‘localhost’,
    ‘username’ => ‘root’,
    ‘password’ => ‘root’,
    ‘database’ => ‘citest’,
    ‘dbdriver’ => ‘mysql’,
    ‘dbprefix’ => ”,
    ‘pconnect’ => TRUE,
    ‘db_debug’ => TRUE,
    ‘cache_on’ => FALSE,
    ‘cachedir’ => ”,
    ‘char_set’ => ‘utf8’,
    ‘dbcollat’ => ‘utf8_general_ci’,
    ‘swap_pre’ => ”,
    ‘encrypt’ => FALSE,
    ‘compress’ => FALSE,
    ‘stricton’ => FALSE,
    ‘failover’ => array(),
    ‘save_queries’ => TRUE
    );

    Cheers!

    1. Hello. I think that if you didn’t autoload the database (or you didn’t load any model until then), then the verify controller will tell you that there is no database connection

      1. Hey Avenirer, how is it going? y, I am a CodIgniter fan and I am a learner. I’ve gone through your tutorials and I’m really loving it. It’s different then the others and really helpful.
        I need some opinion from you that where I can learn a to z CodeIgniter to be a pro like you. And I would really be happy if you give me a reply.

        Thanks.

        1. You’ve got it all wrong. I am not a pro. Pros are the ones that developed the framework. What I can tell you though is that, if you want to take a path towards something you only need the courage to take the first steps. And i mean “steps”, not “step”, because you may find yourself disappointed sometime for not knowing a solution to a given problem. You must persevere. Start by creating simple websites (the “wordpress” kind of sites – only presentation). Everything will come natural after a while. Also, don’t limit yourself to CodeIgniter. Learn PHP. There are functions in PHP that I am still finding out about. Don’t throw yourself to other frameworks like Symfony or Laravel. Those will be too big for a beginner to handle and you will become their prisoner. It’s like learning a new language and forgetting about PHP. Believe me, I’ve tried it… If you really want to learn PHP (but only for that, and not for productivity where speed is important), you may try Simple MVC Framework (http://simplemvcframework.com/php-framework). This one will teach you the hard way what a framework means.

          Learn everyday

          If you want to learn CodeIgniter, the most important thing is to open your browser everyday having the CodeIgniter manual (http://www.codeigniter.com/user_guide/) opened in a tab. I think that the manual put together by the developers is the best thing ever. Although CodeIgniter got to version 3, there are books for previous versions that are still good. Also, new books appeared about CodeIgniter. Buy them. It won’t cost you much, but it will mean a lot to the authors.

          Do something

          Do something. Don’t just follow tutorials. Do a website and work on it. If you just do the same coding that you see in tutorials and then forget about it, you waste your time. Have the courage to start a project in CodeIgniter and keep at it. Soon you will find out that you can’t imagine a website without the framework you like. I can’t stress it enough when I’m saying this. If you want to become a pro, start doing websites.

          Write about what you’ve learned

          Promote what you’ve learned. There are a lot of copy/paste websites that do not explain well. Also CodeIgniter needs promoters and this is the best way some of us can help the framework popularity. So, get yourself a blog and write. Even the simplest things may help some people. By the way, I started this website by writing HTML tutorials? Can you believe it? Besides the fact the you can help teach new beginners, you will feel compelled to learn new things in order to teach new things. Also… it’s good for your CV.

          Buy me a coffee

          You may not believe it but this website is voluntary work. In time, this idealism of doing voluntary work may fade away without coffee… So, on your first salary don’t be shy and do a donation 🙂 I promise to keep helping people. Also, if you have questions you can ask me by writing me at avenir.ro@gmail.com. This way we can learn togheter.

          Have faith

  2. In my case, when trying to access localhost/verify, it just sends me back to welcome page.
    A few things I tried
    1. modifying route.php in ./application/config/development/ (to see if I can get the verify to work) and it presents a “The page isn’t redirecting properly”

    2. blanking the default_route in the route.php -> errors indicating there’s no default route.

    3. Intentionally making some errors in the php files. I just did a “//Some random text” at top of page and it is shown in the welcome page. So CI seems to be able to see the newly created php files.

    I’m now totally stumped 🙁

    1. Don’t worry…
      As you might have seen in the tutorial, we’ve made sure that no-one but us can access that page by verifying if the environment is set to “development” or by verifying that the IP address from which the page is visited is our IP (second block of code). So, to access the page you can either set the environment to “development” or (if you’re environment is in production mode) replace those “XXX.XXX.XXX” with your IP address.

      1. Hey Avenirer

        I find troubleshooting helps a lot, that’s how I learn mostly. Makes me go through the code many times and really trace back step by step what’s going on.

        I found my problem…very newbie problem LOL

        It was in the verify controller…

        if(ENVIRONMENT!==’development’ || $_SERVER[‘REMOTE_ADDR’]==’localhost’)
        {
        $this->load->helper(‘url’);
        redirect(‘/’);

        }

        I was using “127.0.0.1” instead of “localhost”….ah well…

        Other errors follow but I don’t think they are a showstopper for me. At some point i’d like to fix them but I’ll move to step 7 😀

        1. Message: Undefined property: CI_DB_mysqli_driver::$autoinit. Filename: controllers/Verify.php
        2. Message: Undefined index: sess_encrypt_cookie. Filename: views/verify_view.php
        3. Message: Undefined index: sess_match_useragent. Filename: views/verify_view.php

  3. Thanks for the tutorial, after loading the page am getting the following error:
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: sess_match_useragent

    Filename: views/verify_view.php

    Line Number: 299

    Backtrace:

    File: C:\xampp\htdocs\CodeIgniter\application\views\verify_view.php
    Line: 299
    Function: _error_handler

    File: C:\xampp\htdocs\CodeIgniter\application\controllers\Verify.php
    Line: 91
    Function: view

    File: C:\xampp\htdocs\CodeIgniter\index.php
    Line: 292
    Function: require_once

    and

    Database:
    Database is not loaded

    1. This is weird… You should have a sess_match_useragent config key inside your application/config/config.php. Also, when you get a “database is not loaded” that means that you didn’t use any models up until the Verify controlle was run.

  4. Hi Avenirer! First of all, thanks for this site, I working with CI too and get from your site many useful information. Dont u mind if ask u something

    // first of all we need to make sure we are in a development environment or at least that this controller can be seen only by your IP address (you’ll have to replace XXX.XXX.XXX with your IP address, of course)
    if(ENVIRONMENT!==’development’ || $_SERVER[‘REMOTE_ADDR’]==’XXX.XXX.XXX’)

    Here I see next “first of all we need to make sure we are in a development environment” but in code we first check developer environment – with it ok, but then we check IP, so how its working?

    If I understood right in ‘XXX.XXX.XXX’ i will have my ip that allow for access to this page, so if we have development condition and in REMOTE_ADDR my IP I will never see this page, or i missing something?

  5. Great Tut Avenirer,

    Very simple to follow after working through steps 1 – 5 on this step verify section I ran into a few issues using version CI 3.0.4
    application/config/database.php (doesn’t have autoinit so I was getting an error here)

    also from the step you said add ‘database’ to the autoloader, then remove it again, you don’t mention adding ‘database’ back into the autoloader or did I miss something??
    application/config/autoload.php
    $autoload[‘libraries’] = array(‘database’);
    finally in CI 3.0.4
    application/config/development/config.php the following is missing, so it throws an error
    $config[‘sess_encrypt_cookie’] = FALSE;

    After tinkering around a bit I got it all working apart from the uploads, this is where I’m abit confused I setup a vhost environment using xammp on windows 8 under the following:
    C:\xammp\htdocs\sites\my-sites\citest
    and set the following
    application/config/development/config.php
    $config[‘base_url’] = ‘citest’;
    and created a folder in C:\xammp\htdocs\sites\my-sites\citest\uploads so the structure is as follows:

    citest
    – application
    — cache
    — config
    – uploads (is this the correct place to put it as I keep getting the following citest/uploads is not writable)
    – system
    I’ve changed all the permissions possible and I still can’t get it writeable???

    Thanks once again, as it’s a good starting base for everyone this, it’s just the uploads have got me beat…

    Cheers

    Mal

  6. Thanks for the terrific tutorial… I’m getting an error :
    Unable to load the requested file: helpers/my_loader_helper.php

    Not sure where it’s coming from. I don’t have anything in the helpers folder. And I don’t see where out files are pointing to the a helper class. Could the issue be that I’m including the prefix “MY_” in the subclass when I don’t need it, because it’s added by the config file?
    or should I change :
    $data[‘loaded_classes’] = $this->load->get_loaded_classes();
    to be
    $this->load->helper(‘MY_loader’);
    $data[‘loaded_classes’] = $this->load->get_loaded_classes();

    Thoughts?

  7. Hello
    It is possible to add to this table, additionalinformation.
    I tested:
    * $route[‘default_controller’]
    and
    * $route[‘404_override’]
    Like this, for example:
    $defaut_page = $this->router->default_controller;
    $page_404 = $this->router->routes[‘404_override’];

  8. For the next newbie,

    If you get a
    “404 Error – Page Not found” when you load the url http://localhost/verify

    It means the class is not found.

    In my case , this was because of;

    class Welcome extends CI_Controller {

    which promptly edited to;

    class Verify extends CI_Controller {

  9. Instead of the whole DB password, you can mask out the centre 1/3

    $db_password_length = strlen($this->db->password) / 3;
    $db_password_mask = '';
    for($i=0;$idb->password,$db_password_mask,$db_password_length,$db_password_length);

  10. $db_password_length = strlen($this->db->password) / 3;
    $db_password_mask = '';
    for($i=0;$i<$db_password_length;$i++) {
    $db_password_mask .= '*';
    }
    $db_password_masked = substr_replace($this->db->password,$db_password_mask,$db_password_length,$db_password_length);

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.