note 115890 added to reserved.variables.get

From: Date: Fri, 10 Oct 2014 13:11:03 +0000
Subject: note 115890 added to reserved.variables.get
Groups: php.notes 
Request: Send a blank email to php-notes+get-200617@lists.php.net to get a copy of this message
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 ;) ---- Server IP: 72.52.91.14 Probable Submitter: 109.92.170.35 ---- Manual Page -- http://php.net/manual/en/reserved.variables.get.php Edit -- https://master.php.net/note/edit/115890 Del: integrated -- https://master.php.net/note/delete/115890/integrated Del: useless -- https://master.php.net/note/delete/115890/useless Del: bad code -- https://master.php.net/note/delete/115890/bad+code Del: spam -- https://master.php.net/note/delete/115890/spam Del: non-english -- https://master.php.net/note/delete/115890/non-english Del: in docs -- https://master.php.net/note/delete/115890/in+docs Del: other reasons-- https://master.php.net/note/delete/115890 Reject -- https://master.php.net/note/reject/115890 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200617) next »