note 115890 deleted from reserved.variables.get by peehaa

From: Date: Sun, 28 Apr 2019 10:58:37 +0000
Subject: note 115890 deleted from reserved.variables.get by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210847@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- There is a smart way to protect the $ _GET input from malicious injection and options for inserting default values: <?php // Smart GET function public function GET($name=NULL, $value=false, $option="default") { $option=false; // Old version depricated part $content=(!empty($_GET[$name]) ? trim($_GET[$name]) : (!empty($value) && !is_array($value) ? trim($value) : false)); if(is_numeric($content)) return preg_replace("@([^0-9])@Ui", "", $content); else if(is_bool($content)) return ($content?true:false); else if(is_float($content)) return preg_replace("@([^0-9\,\.\+\-])@Ui", "", $content); else if(is_string($content)) { if(filter_var ($content, FILTER_VALIDATE_URL)) return $content; else if(filter_var ($content, FILTER_VALIDATE_EMAIL)) return $content; else if(filter_var ($content, FILTER_VALIDATE_IP)) return $content; else if(filter_var ($content, FILTER_VALIDATE_FLOAT)) return $content; else return preg_replace("@([^a-zA-Z0-9\+\-\_\*\@\$\!\;\.\?\#\:\=\%\/\ ]+)@Ui", "", $content); } else false; } /* DEFAULT: $_GET['page']; SMART: GET('page'); // return value or false if is null or bad input */ ?> I hope this is helpful. Cheers ;)

« previous php.notes (#210847) next »