Anti-Moronic Posted January 21, 2010 Share Posted January 21, 2010 Say I have: site.com/index.php?v=var&v=12 Is there a way to only parse the first occurrence? Link to comment https://forums.phpfreaks.com/topic/189264-is-there-a-way-to-protect-get-query-parameters-being-overwriten/ Share on other sites More sharing options...
gizmola Posted January 21, 2010 Share Posted January 21, 2010 The $_SERVER['QUERY_STRING'] variable gives you the original query string, which you are free to parse up and handle yourself. explode() using the '&' should work pretty well to get the name=value pairs. Link to comment https://forums.phpfreaks.com/topic/189264-is-there-a-way-to-protect-get-query-parameters-being-overwriten/#findComment-999187 Share on other sites More sharing options...
Anti-Moronic Posted January 21, 2010 Author Share Posted January 21, 2010 Thanks, I just found a solution to it somewhere else. Quite a useful nifty little function: $query = explode('&', $_SERVER['QUERY_STRING']); $params = array(); foreach( $query as $param ) { list($name, $value) = explode('=', $param); $params[urldecode($name)][] = urldecode($value); } I then parse those results and only use the first in the array (i.e. first occurrence of any given query string variable). Thanks for the input! Link to comment https://forums.phpfreaks.com/topic/189264-is-there-a-way-to-protect-get-query-parameters-being-overwriten/#findComment-999204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.