PHP Universal Anti-injection security code

Source: Internet
Author: User
Tags foreach array key php file return
Safety | anti-injection Brief:
/*************************

Description

Determines whether the passed variable contains illegal characters

such as $_post, $_get

Function:

Anti-injection

**************************/

<?php

Illegal characters to filter

$ArrFiltrate =array ("'", ";", "union");

The URL to jump after an error is not filled in the default previous page

$STRGOURL = "";

Whether the value in the array exists

function Funstringexist ($StrFiltrate, $ArrFiltrate) {

foreach ($ArrFiltrate as $key => $value) {

if (eregi ($value, $StrFiltrate)) {

return true;

}

}

return false;

}

Merging $_post and $_get

if (function_exists (Array_merge)) {

$ArrPostAndGet =array_merge ($HTTP _post_vars, $HTTP _get_vars);

}else{

foreach ($HTTP _post_vars as $key => $value) {

$ArrPostAndGet []= $value;

}

foreach ($HTTP _get_vars as $key => $value) {

$ArrPostAndGet []= $value;

}

}

Verify Start

foreach ($ArrPostAndGet as $key => $value) {

if (Funstringexist ($value, $ArrFiltrate)) {

echo "<script language=\" javascript\ ">alert (\" NEEAO hint, illegal character \ ");</script>";

if (empty ($STRGOURL)) {

echo "<script language=\" javascript\ ">history.go ( -1);</script>";

}else{

echo "<script language=\" javascript\ ">window.location=\" ". $StrGoUrl." \ ";</script>";

}

Exit

}

}

?>
Save As Checkpostandget.php

Then add include ("checkpostandget.php") in front of each PHP file;



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.