The security analysis of CI framework _php Example

Source: Internet
Author: User
Tags codeigniter zend framework

This paper analyzes the security of CI framework. Share to everyone for your reference, specific as follows:

People who have used the CI framework know that the CI framework can greatly shorten your code. In fact, the CI framework can improve the security of your website.

Preventing attacks on the database

Data entry can cause many problems. Because of the limitations of HTML and the database, the data always contains a specific symbol-for example, ellipses and quotes-may cause your database to be attacked and eventually you will end up with unpredictable results.

The solution is to process the data before it is stored in the database. Doing so would waste some system time and add some extra coding.

The form helper function for CI automatically completes these tasks. So, when you write an input box:

echo form_input (' username ', ' johndoe ');

CI also implicitly performs the following validation functions:

function Form_prep ($str = ')
{
  if ($str = = ')
  {return
    ';
  }
  $temp = ' __temp_ampersands__ ';
  Replace entities to temporary markers so
  ,/Htmlspecialchars won ' t mess them up
  $str = preg_replace ("/& ; # (\d+);/"," $temp \\1; ", $str);
  $str = Preg_replace ("/& (\w+);/", "$temp \\1;", $str);
  $str = Htmlspecialchars ($STR);
  In the case Htmlspecialchars misses.
  $str = Str_replace (Array ("'", ' "), Array (" "," ""), $str);
  Decode the temp markers back to Entities
  $str = Preg_replace ("/$temp (\d+);/", "&#\\1;", $str);
  $str = Preg_replace ("/$temp (\w+);/", "&\\1;", $str);
  return $str;
}

The above function captures special characters such as "&" so that it does not cause confusion when your page is submitted. You should know that some characters can cause problems.

Not all users will be able to enter the required information in a compliant way, and you cannot know who is using the browser to enter information, what they are thinking and doing. You can use CI to prevent input of information that does not meet your requirements. Of course, you don't have to know how CI is doing it behind the scenes, you just need to simply enter the following code:

echo form_input (' username ', ' johndoe ');

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.