Saturday, January 07, 2017

template inheritance in codeigniter

hi,

when it comes to $this->load->view('view_file') in controller, usually i saw something like this.

$this->load->view('header');
$this->load->view('body', $data);
$this->load->view('footer');

its to maintain the design template that they create or use. for me, ill try to make my controller clean as possible. its easier for me in case i need to debug my code. so the code in my controller must be as minimal as it can be. only a form process and a few things that is very important should be there in the controller.

in order to do that, i need help from a helper which is

template inheritance
. u can download n study from this site.
http://www.phpti.com

pls do take note, its not the same as

Smarty template inheritance
because the file i meant was based on
Django project

u can get the file from this link.

template_inheritance_helper.php

enjoy!

Wednesday, January 04, 2017

Data sanitizing, cross scripting and XSS filtering

hi,

its been a while. im rusted a lot. havent done codeigniter n php for nearly 2 years..

ok, im going to share how i sanitized a data from user before that data can be taken n record to the database. to validate and sanitized data is quite a tedious process if we do it from a scratch.

usually its depends a lot of regex. for example, how we make sure that our user insert his email to our input?
we need to know the pattern of the input. in php this is the regex for any email address.

/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

credit to Email Address Regular Expression That 99.99% Works

that makes our code r very long n its hard to track.

when u r in the process of debugging. just use the built in function that comes with the codeigniter. simple right?

ok, we come to cross scripting or XSS features. this is quite intesting topic for me cos previously i havent thought how "naughty people" violate the whole system website untill i reach this page. Cross-site Scripting (XSS) Attack. u can learn more cos im not going to cover this topic, whats important to me is that i must use this feature in codeigniter..haha

well, enjoy my 2 part of clips... thank you.