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)? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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). Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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.'; Quote Link to comment Share on other sites More sharing options...
Isityou Posted March 6, 2008 Author Share Posted March 6, 2008 Jesus Loves You, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.