Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. function chk_glob($identifiers, $super, $db_escape = 1)
  2. {
  3.     /*
  4.         Using $_GET, $_POST, $_COOKIE, $_SERVER arrays are annoying
  5.         because before you use them you have the check that the value
  6.         exists. Then you have to escape it so there is a lot of code
  7.         duplication and it's boring. There is also no succinct way of
  8.         knowing whether the allocation was successful. This function
  9.         solves that . . . and to stop duplication further it works on
  10.         a list of idenitifers.
  11.     */
  12.     $identifiers = explode(",", $identifiers);
  13.     $status = 1;
  14.     foreach($identifiers as $identifier)
  15.     {
  16.         global $$identifier;
  17.         /*
  18.            Variable variables cannot be used with super globals hence
  19.            we copy it to a non-super global variable and free it.
  20.         */
  21.         if($db_escape)
  22.         {
  23.            
  24.             $$identifier = empty($super["$identifier"]) ? "" : mysql_escape_string(urldecode($super["$identifier"]));
  25.         }
  26.         else
  27.         {
  28.             $$identifier = empty($super["$identifier"]) ? "" : urldecode($super["$identifier"]);
  29.         }
  30.        
  31.         if(empty($$identifier))
  32.         {
  33.             $status = 0;
  34.         }
  35.     }
  36.     return $status;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement