This article mainly introduces the security principle of using the addslashes function escape in PHP, and analyzes the usage of the addslashes function and the limitations of the ecshop user-defined function addslashes_deep, which is very useful, for more information about how to use the addslashes function escape in PHP, see the following example. Share it with you for your reference. The specific analysis is as follows:
Let's take a look at the prototype of addslashes_deep in ECshop.
The code is as follows:
Function addslashes_deep ($ value ){
If (empty ($ value )){
Return $ value; // if it is null, return directly;
} Else {
Return is_array ($ value )? Array_map ('addslashes _ deep ', $ value): addslashes ($ value );
} // Recursively process the array until all array elements are traversed;
}
The addslashes_deep function is no problem, but you must pay attention to it when using it.
Today, we also saw a BUG injection vulnerability on the internet about using this function.
When this function references the callback function addslashes, only the data values are escaped. Therefore, if the user references the array key for specific processing during this process, there is a risk of $ key injection, in this case, you can change the addslashes_deep function to escape the key value at the same time, or explicitly do not reference the key content during use.
I hope this article will help you with PHP programming.