Auto-loading Resources

CodeIgniter comes with an “Auto-load” feature that permits libraries, helpers, and models to be initialized automatically every time the system runs. If you need certain resources globally throughout your application you should consider auto-loading them for convenience.

The following items can be loaded automatically:

1) Classes found in the libraries/ directory
2) Helper files found in the helpers/ directory
3) Custom config files found in the config/ directory
4) Language files found in the system/language/ directory
5) Models found in the models/ folder

To autoload resources, open the application/config/autoload.php file and add the item you want loaded to the autoload array. You’ll find instructions in that file corresponding to each type of item.

Do not include the file extension (.php) when adding items to the autoload array.

Additionally, if you want CodeIgniter to use a Composer auto-loader, just set $config[‘composer_autoload’] to TRUE or a custom path in application/config/config.php.

Get elapsed time in php

Elapsed time is simply the amount of time that passes from the beginning of an event to its end. In this lesson, you will learn how to solve for elapsed time and explore how it can be used in your everyday life.

In this post we will show how to get elapsed time in php. We will use a function where you just need to pass the time string which you want to compare from the current timestamp.

See the code below

Pass your date time string which you need to compare and you will get the result you are looking for.

How to create a file using php

In this post you will learn how to create a file using PHP. In PHP, a file is created using a command that is also used to open files.

In PHP the fopen function is used to open files. However, it can also create a file if it does not find the file specified in the function call. So if you use fopen on a file that does not exist, it will create it. Read More

Security helper in codeigniter

Security Helper

The Security Helper file contains security related functions.

Loading this Helper

This helper is loaded using the following code:

Available Functions

The following functions are available:

xss_clean($str[, $is_image = FALSE])

  • $str (string) – Input data
  • $is_image (bool) – Whether we’re dealing with an image
  • Returns:XSS-clean string
    Return type:string

    Provides Cross Site Script Hack filtering.

    This function is an alias for CI_Input::xss_clean().


  • $filename (string) – Filename
  • Returns:Sanitized file name
    Return type:string

    Provides protection against directory traversal.

    This function is an alias for CI_Security::sanitize_filename().

    do_hash($str[, $type = ‘sha1’])

  • $str (string) – Input
  • $type (string) – Algorithm
  • Returns:Hex-formatted hash
    Return type:string

    Permits you to create one way hashes suitable for encrypting passwords. Will use SHA1 by default.


    This function was formerly named dohash(), which has been removed in favor of do_hash().

    This function is DEPRECATED. Use the native hash() instead.

    do_hash($str[, $type = ‘sha1’])

  • $str (string) – Input string
  • Returns:The input string with no image tags
    Return type:string

    This is a security function that will strip image tags from a string. It leaves the image URL as plain text.


    This function is an alias for CI_Security::strip_image_tags()


  • $str (string) – Input string
  • Returns:Safely formatted string
    Return type:string

    This is a security function that converts PHP tags to entities.

    xss_clean() does this automatically, if you use it.


    Create derivers in codeigniter

    Creating Drivers

    Driver Directory and File Structure

    Sample driver directory and file structure layout:


    Note: In order to maintain compatibility on case-sensitive file systems, the Driver_name directory must be named in the format returned by ucfirst().

    Note: The Driver library’s architecture is such that the subclasses don’t extend and therefore don’t inherit properties or methods of the main driver.