This article introduces a common php method for getting variable values globally. For more information, see. We use foreach to traverse the variables to determine whether the cookie, post, and get methods are used. in this way, we only need to use my_addslas
This article introduces a common php method for getting variable values globally. For more information, see.
The instance code is as follows:
- Function my_addslashes ($ string, $ force = 0 ){
- ! Defined ('Magic _ QUOTES_GPC ') & define ('Magic _ QUOTES_GPC', get_magic_quotes_gpc ());
- If (! MAGIC_QUOTES_GPC | $ force ){
- If (is_array ($ string )){
- Foreach ($ string as $ key => $ val ){
- $ String [$ key] = my_addslashes ($ val, $ force );
- }
- } Else {
- $ String = addslashes ($ string );
- }
- }
- Return $ string;
- }
- Foreach (array ('_ cookies',' _ post', '_ get') as $ _ request ){
- Foreach ($ _ request as $ _ key => $ _ value ){
- $ _ Key {0 }! = '_' & $ _ Key = my_addslashes ($ _ value );
- }
- }
- Echo $ urls;
- ?>
Here we use foreach to traverse the variables to determine whether the cookie, post, and get methods are used. in this way, when I use my_addslashes directly, the difference is that the values from post, get, and cookie are automatically different.