Isityou Posted March 5, 2008 Share Posted March 5, 2008 I want to get the parameters users type in the URL, for example say a user types: http://www.website.com/index.php?var1=test&var2=test1&var3=test2 How do I get the name of the variable the user declared (var1,var2,var3)? Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/ Share on other sites More sharing options...
MasterACE14 Posted March 5, 2008 Share Posted March 5, 2008 This question has been asked many many times before please check the forum before posting! ----- this is what you're after: <?php echo $_GET["var1"]; outputs: test Regards ACE Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483725 Share on other sites More sharing options...
redarrow Posted March 5, 2008 Share Posted March 5, 2008 if your going to use varables in the url please also look at mod_rewite for secuity.. http://www.workingwith.me.uk/articles/scripting/mod_rewrite Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483727 Share on other sites More sharing options...
Isityou Posted March 5, 2008 Author Share Posted March 5, 2008 Please read the question thoroughly before replying. I do not want the value of the variable I want the actual name of the variable (var1, var2, var3). Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483937 Share on other sites More sharing options...
kenrbnsn Posted March 5, 2008 Share Posted March 5, 2008 The variable names are all indexes to the $_GET array, so you could use a foreach loop to get them: <?php foreach ($_GET as $var => $val) echo 'The variable ' . $var . ' has the value [' . $val . ']<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483948 Share on other sites More sharing options...
Isityou Posted March 5, 2008 Author Share Posted March 5, 2008 How about unwanted variables, say form input? Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483951 Share on other sites More sharing options...
discomatt Posted March 5, 2008 Share Posted March 5, 2008 You use the loop, check if the variables shouldn't be there, then fail/exit/report if they do. Pretty straight forward $varsyouwant = array('var1', 'var2', 'var3'); foreach ($_GET as $var => $val) if (!in_array($var, $varsyouwant) ) echo 'GET variable "' . $var . '" should not be there.'; Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-483955 Share on other sites More sharing options...
Isityou Posted March 6, 2008 Author Share Posted March 6, 2008 Jesus Loves You, thanks. Link to comment https://forums.phpfreaks.com/topic/94445-url-variables/#findComment-484474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.