note 105061 added to reserved.variables.get

From: Date: Mon, 25 Jul 2011 20:09:44 +0000
Subject: note 105061 added to reserved.variables.get
Groups: php.notes 
Request: Send a blank email to php-notes+get-181865@lists.php.net to get a copy of this message
You can use this function to remove any $_GET variables out of your URL, it takes an array off strings(the names keys of the $_GET you wish to remove) and returns the url with the ones specified removed <?php function getUrlWithout($getNames){ $url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $questionMarkExp = explode("?", $url); $urlArray = explode("&", $questionMarkExp[1]); $retUrl=$questionMarkExp[0]; $retGet=""; $found=array(); foreach($getNames as $id => $name){ foreach ($urlArray as $key=>$value){ if(isset($_GET[$name]) && $value==$name."=".$_GET[$name]) unset($urlArray[$key]); } } $urlArray = array_values($urlArray); foreach ($urlArray as $key => $value){ if($key<sizeof($urlArray) && $retGet!=="") $retGet.="&"; $retGet.=$value; } return $retUrl."?".$retGet; } ?> Example current url is http://www.thisIsAnExample.net/index.php?getVar1=Something&getVar2=10&getVar3=ok <?php echo getUrlWithout(array("getVar1","getVar3")); //result will be "http://www.thisIsAnExample.net/index.php?getVar2=10" ?> ---- Server IP: 69.147.83.197 Probable Submitter: 109.132.161.163 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.get.php Edit -- https://master.php.net/note/edit/105061 Del: integrated -- https://master.php.net/note/delete/105061/integrated Del: useless -- https://master.php.net/note/delete/105061/useless Del: bad code -- https://master.php.net/note/delete/105061/bad+code Del: spam -- https://master.php.net/note/delete/105061/spam Del: non-english -- https://master.php.net/note/delete/105061/non-english Del: in docs -- https://master.php.net/note/delete/105061/in+docs Del: other reasons-- https://master.php.net/note/delete/105061 Reject -- https://master.php.net/note/reject/105061 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181865) next »