1<?php 2 3/** 4 * Read a query parameter 5 * If this parameter is not specified, return the default value 6 * Remove magic quotes, if they're enabled 7 * 8 */ 9 10function get_var($name, $array, $maxlength=255, $default=null) { 11 /** 12 * Check if this parameter is specified 13 */ 14 if (!isset($array[$name])) { return $default; }; 15 16 /** 17 * Read initial value of parameter 18 */ 19 $data = $array[$name]; 20 21 if (is_array($data)) { 22 /** 23 * Arrays should be processed element-by-element 24 */ 25 if (get_magic_quotes_gpc()) { 26 foreach ($data as $key => $value) { 27 $data[$key] = stripslashes($data[$key]); 28 }; 29 }; 30 } else { 31 /** 32 * Remove slashes added by magic quotes option 33 */ 34 if (get_magic_quotes_gpc()) { 35 $data = stripslashes($data); 36 }; 37 38 /** 39 * Limit maximal length of passed data 40 */ 41 $data = substr($data, 0, $maxlength); 42 }; 43 44 return $data; 45} 46?>