Php function code that filters input information safely. Copy the code as follows: defineconstanntsforinputreadingdefine (INPUT_GET, 0x0101); define (INPUT_POST, 0x0102); define (INPUT_GPC, 0x0103); *** Readinputvalueand
The code is as follows:
// Define constanets 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
* @ 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)
The http://www.bkjia.com/PHPjc/325512.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325512.htmlTechArticle code is as follows: // define constanets for input reading define ('input _ get', 0x0101); define ('input _ post', 0x0102 ); define ('input _ GPC ', 0x0103);/*** Read INPUT value and...