PHP Prevent SQL injection Filter paging parameter instance _php tips

Source: Internet
Author: User

The example in this article describes how PHP prevents filtering of paging parameters in SQL injection. Share to everyone for your reference. The specific analysis is as follows:

In the case of network security, do not believe any input information on the network, for any input information we must filter the parameters. For this, let's take a look at the following examples:

Copy Code code as follows:
$this->load->library (' pagination ');
$config [' base_url '] = Site_url (). '/guest/show ';
$config [' total_rows '] = $c;
$config [' per_page '] = $pernum = 15;
$config [' uri_segment '] = 3;
$config [' use_page_numbers '] = TRUE;
$config [' first_link '] = ' first page ';
$config [' last_link '] = ' last page ';
$config [' num_links '] = 5;
$this->pagination->initialize ($config);
if (! $this->uri->segment (3)) {
$currentnum = 0;
} else {
$currentnum = Is_numeric ($this->uri->segment (3))? (Intval ($this->uri->segment (3)-1)) * $pernum: 0;
}

$current _page=is_numeric ($this->uri->segment (3))? Intval ($this->uri->segment (3)): 1;
if ($current _page) {
$data [' title '] = ' first '. $current _page. ' Page-message book-Anti-SQL injection test ';
}
else{
$data [' title '] = ' message book-Anti-SQL injection test ';
}

$data [' liuyan '] = $this->ly->getly ($pernum, $currentnum);

which

Copy Code code as follows:
$current _page=is_numeric ($this->uri->segment (3))? Intval ($this->uri->segment (3)): 1;
$currentnum = Is_numeric ($this->uri->segment (3))? (Intval ($this->uri->segment (3)-1)) * $PERNUM;

These two sentences determine whether the parameter is a number. Prevents illegal character input.

I hope this article will help you with your PHP program design.

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.