Php prevents SQL injection to filter paging parameter instances. SQL paging _ PHP Tutorial

Source: Internet
Author: User
Php prevents SQL injection to filter paging parameter instances. Php prevents SQL injection and filters paging parameters. This article describes how php prevents SQL injection from filtering paging parameters. Share it with you for your reference. The specific analysis is as follows: php prevents SQL injection to filter paging parameter instances, and SQL paging

This example describes how to prevent paging parameters from being filtered by SQL injection in php. Share it with you for your reference. The specific analysis is as follows:

For network security, do not trust any input information on the network. we must filter parameters for any input information. For this purpose, let's take a look at the following example:

The code is 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'] = 'title'. $ 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 );


Where:

The code is 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;


The two statements determine whether the parameter is a number. Prevents invalid characters.

I hope this article will help you with PHP programming.


Php filter SQL injection, beginner

In the PHP4 environment, I wrote a code against SQL injection, which is compatible with PHP5. You are welcome to modify the code and use it.
The code is as follows:
/*
Sqlin anti-injection class
*/
Class sqlin
{

// Dowith_ SQL ($ value)
Function dowith_ SQL ($ str)
{
$ Str = str_replace ("and", "", $ str );
$ Str = str_replace ("execute", "", $ str );
$ Str = str_replace ("update", "", $ str );
$ Str = str_replace ("count", "", $ str );
$ Str = str_replace ("chr", "", $ str );
$ Str = str_replace ("mid", "", $ str );
$ Str = str_replace ("master", "", $ str );
$ Str = str_replace ("truncate", "", $ str );
$ Str = str_replace ("char", "", $ str );
$ Str = str_replace ("declare", "", $ str );
$ Str = str_replace ("select", "", $ str );
$ Str = str_replace ("create", "", $ str );
$ Str = str_replace ("delete", "", $ str );
$ Str = str_replace ("insert", "", $ str );
$ Str = str_replace ("'", "", $ str );
$ Str = str_replace ("", "", $ str );
$ Str = str_replace ("", "", $ str );
$ Str = str_replace ("or", "", $ str );
$ Str = str_replace ("=", "", $ str );
$ Str = str_replace ("% 20", "", $ str );
// Echo $ str;
Return $ str;
}
// Aticle () anti-SQL injection function
Function sqlin ()
{
Foreach ($ _ GET as $ key => $ value)
{
$ _ GE ...... remaining full text>

PHP anti-SQL injection

Basically, I use the htmlspecialchars () and mysql_escape_string () methods to process the obtained parameters ..

Examples in this article describes how php can prevent filtering paging parameters in SQL injection. Share it with you for your reference. The specific analysis is as follows :...

Related Article

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.