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:
Copy codeThe 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:
Copy codeThe 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:
<? Php
/*
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 ..