360 general protection filters user input data for defense-PHP source code

Source: Internet
Author: User
360 general protection filters user input data to prevent injection:

1. Save the following code as a 360_safe3.php file and upload it to the Directory of the file to be included.

2. introduce the above 360_safe3.php File: require_once ('2017 _ safe3.php') on the page ');

If you want to protect your website against website injection, add it to a public file on the website, such as the database link file config. inc. php!

 Error number:[$ Errno], error on line $ errline in $ errfile
"; Die () ;}set_error_handler (" customError ", E_ERROR); $ getfilter =" '| (and | or) \ B. +? (>|<|=| In | like) |\/\\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) "; $ postfilter =" \ B (and | or) \ B. {1, 6 }? (=|>|<|\\ Bin \ B |\\ blike \ B) |\\/ \\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) "; $ cookiefilter =" \ B (and | or) \ B. {1, 6 }? (=|>|<|\\ Bin \ B |\\ blike \ B) |\\/ \\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) "; function StopAttack ($ StrFiltKey, $ StrFiltValue, $ ArrFiltReq) {if (is_array ($ StrFiltValue) {$ StrFiltValue = implode ($ StrFiltValue);} if (preg_match ("/". $ ArrFiltReq. "/is", $ StrFiltValue) = 1) {// slog ("

Operation IP address: ". $ _ SERVER [" REMOTE_ADDR "]."
Operation Time: ". strftime (" % Y-% m-% d % H: % M: % S ")."
Operation page: ". $ _ SERVER [" PHP_SELF "]."
Submission method: ". $ _ SERVER [" REQUEST_METHOD "]."
Parameter submitted: ". $ StrFiltKey ."
Submit data: ". $ StrFiltValue); print" 360 websec notice: Illegal operation! "; Exit () ;}// $ ArrPGC = array_merge ($ _ GET, $ _ POST, $ _ COOKIE ); foreach ($ _ GET as $ key = >$ value) {StopAttack ($ key, $ value, $ getfilter);} foreach ($ _ POST as $ key => $ value) {StopAttack ($ key, $ value, $ postfilter);} foreach ($ _ COOKIE as $ key => $ value) {StopAttack ($ key, $ value, $ cookiefilter);} if (file_exists ('update360. php ') {echo "please rename the file update360.php to prevent hackers from using
"; Die ();} function slog ($ logs) {$ toppath = $ _ SERVER [" DOCUMENT_ROOT "]. "/log.htm"; $ Ts = fopen ($ toppath, "a +"); fputs ($ Ts, $ logs. "\ r \ n"); fclose ($ Ts) ;}?>

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.