Codeigniter custom 404 page and show_404 function

If your looking to cusomize the default 404 page thats displayed when a user enters an invalid URL, with your codeigniter application, there are a few different way in which you can do this.

Codeigniter Default 404

Codeigniter Default 404

So your ready to modify your default 404 page for your codeigniter application?

error_404.php
To modify the default page open up the default error_404.php in your faviorte text/html editor and make the changes you would like.

The default 404 file is located at “/application/errors/error_404.php”

If your looking to get a bit more creative and wrap your 404 page in a template we can do this by extending CI_Exceptions.

First, create a file in your “/applications/core/” directory labeled “MY_Exceptions”, unless you have changed the default subclass_prefix in the “/applications/config/config.php” file, by default it should look like this:

Take notice that “MY_” is uppercase, the file you created in the core directory will need to reflect this exactly. Your file should be labeled exactly as shown: “MY_Exceptions.php”

Again if you have changed this prefix in your config file you will need to label your file to reflect the same prefix, i.e.

Would be: “YouR_Exceptions.php”

Now open that file in you text editor and add the following code:

If your curious about the ” $CI =& get_instance(); “ you can read more about that in the codeigniter manual here:
http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

I must also point out that in the above script im using a template file located in “/includes/template/” and am passing data to the file. the below is an example of how this file might look.

Your template file may be a little different. The main thing to notice here is the variable “$main_content” . This is the variable passed containing the path to our error_404.php page in our MY_Exceptions.php file.

Now create a directory in your “/application/views/” labeled “errors” and create a file labeled “error_404.php”.

Now open that file and place the following code inside and save it.

Now in your controller all you have to do is call the show_404() function like so:

Enter an invalid URL and you should now see your new custom 404 page loaded in your template.

Custom 404 Page with Tempalte

Custom 404 Page with Tempalte

Posted in Codeigniter, PHP | Comments Off

Codeigniter and Query Results MySQL Error 1064

Although the title refers to Codeigniter this applies to anytime you run a query and get the MySQL Error 1064.

If your trying to Query results with MySQL and get and Error 1064 more than likely you forgot to escape something in your database results.

Take the following:

In Codeigniter you might run a query like this:

Everything may look ok but in fact you forgot one importint thing! To escape the value you querying, the email address in this case.

Your code should look like this:

Notice the “.$this->db->escape($email).” ? Granted this is a specific way to query for Codeigniter however, your query statement should always use an escaped value when dealing with emails or other strings that might need escaping.

An alternative way of escaping characters with Codeigniter is using bindings. Take the following for example:

Here we have used a question mark as a place holder and placed our values in an array. By doing this Codeigniter will automatically escape the values.

If your using something other than Codeigniter you can simply use the following:

mysql_real_escape_string(); Note: Use of this extension is discouraged.

Instead you should be using one of the following:

mysqli::real_escape_string();
or
php’s PDO_MYSQL

Posted in Codeigniter | Tagged , , , | Comments Off

Installing No-IP 2 Ubuntu 12.04

If your trying to install No-IP2 on Ubuntu 12.04, from source and get the error message “make: gcc: Command not found” or a similar message, you may not have the C++ Compiler installed.

“To install the gcc and g++ compilers, you will need the build-essential package. This will also install GNU make.

build-essential contains a list of packages which are essential for building Ubuntu packages including gcc compiler, make and other required tools.”

At the Terminal enter the following:

Now, you should able to compile software using C / C++ compilers.

Source quoted from Ubuntu Documentation. Find out more about compilers here: https://help.ubuntu.com/community/InstallingCompilers

Now your ready to install No-IP2 by entering the following:

After that you should be prompted to enter your user name and password! That’s it, you should now be up and running with your No-IP DUC!

Posted in Daily Post | Tagged , , , , | Comments Off

New Webmin Look?

I recently updated my webmin installation to 1.60 on didn’t notice any changes, however after I decided it was time for a fresh and well deserved re-install of the Ubuntu, I re-installed Webmin with the current version and after installing noticed a fresh and very clean look:

Webmin Version 1.60 Theme

The New theme for Webmin

If your wondering you can still use the previous themes, by going to Webmin-> Webmin Configuration-> Webmin Themes and selecting one of the previous themes.

Suppose if I had checked prior to reinstalling the new theme would have been there, I just never thought to look… That will teach me! :)

Posted in Daily Post | Tagged , | Comments Off