PHP function Code _php technique for safe filtering of input information

Source: Internet
Author: User
Tags html tags
Copy Code code as follows:

Define constannts for input reading
Define (' Input_get ', 0x0101);
Define (' Input_post ', 0x0102);
Define (' INPUT_GPC ', 0x0103);

/**
* Read input value and convert it for internal use
* Performs stripslashes () and CharSet conversion if necessary
*
* @param string Field name to read
* @param int Source to get value from (GPC)
* @param boolean Allow HTML tags in field value
* @param string Charset to convert into
* @return String Field value or NULL if not available
*/
function Get_input_value ($fname, $source, $allow _html=false, $charset =null) {
$value = NULL;

if ($source = = Input_get && isset ($_get[$fname]))
$value = $_get[$fname];
else if ($source = = Input_post && isset ($_post[$fname]))
$value = $_post[$fname];
else if ($source = = INPUT_GPC) {
if (Isset ($_post[$fname]))
$value = $_post[$fname];
else if (Isset ($_get[$fname]))
$value = $_get[$fname];
else if (Isset ($_cookie[$fname]))
$value = $_cookie[$fname];
}

if (empty ($value))
return $value;

Strip single Quotes if Magic_quotes_sybase is enabled
if (Ini_get (' magic_quotes_sybase '))
$value = Str_replace ("" "," "", $value);
Strip slashes if magic_quotes enabled
else if (GET_MAGIC_QUOTES_GPC () | | get_magic_quotes_runtime ())
$value = Stripslashes ($value);

Remove HTML tags if not allowed
if (! $allow _html)
$value = Strip_tags ($value);

Convert to Internal charset
return $value;
}

Usage: get_input_value (' _uid ', input_get)

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.