Escape the input variables.

Source: Internet
Author: User

 

First look at the code implementation:

/* Escape the input variables. */If (! Get_magic_quotes_gpc () {If (! Empty ($ _ Get) {$ _ Get = addslashes_deep ($ _ Get);} If (! Empty ($ _ post) {$ _ post = addslashes_deep ($ _ post);} $ _ cookie = addslashes_deep ($ _ cookie ); $ _ Request = addslashes_deep ($ _ request );} /*** escape special characters in the variable in recursion mode ** @ access public * @ Param mix $ value ** @ return mix */function addslashes_deep ($ value) {If (empty ($ value) {return $ value;} else {return is_array ($ value )? Array_map ('addslashes _ deep ', $ value): addslashes ($ value );}}

 

 

Function explanation:

Get_magic_quotes_gpc ():

Function: obtain the value of magic_quotes_gpc, a PHP environment variable.

Syntax: Long get_magic_quotes_gpc (void );

Return Value: Long Integer

Function Type: PhP System Function

This function obtains the magic_quotes_gpc (GPC, get/post/cookie) value set in the PHP environment. If the return value is 0, this function is disabled. If the return value is 1, this function is enabled. When magic_quotes_gpc is enabled, all '(single quotation marks),' (double quotation marks), \ (backslash), and null characters are automatically converted to overflow characters containing the backslash.

The get_magic_quotes_gpc function is: whether to add a backslash to the double quotation mark (") or backslash (backslash) in the data sent from get, post, or cookie.

If get_magic_quotes_gpc = on, 1 is returned. The PHP parser automatically adds the Escape Character "\" to the post, get, and cookie data to ensure that the data will not cause the program, in particular, database statements may cause fatal errors due to pollution caused by special characters.

 

Addslashes ():

 

Function: uses a backslash to reference a string.

 

Syntax: String addslashes (string Str)

 

Return Value: Return string. This string must be followed by a backslash before certain characters for database query statements. These characters are single quotation marks ('), double quotation marks ("), backslash (), and (null ).

 

 

 

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.