I remember I used a command to get all the variables from an URL. I don`t want to use separate $_GET for every single variable. Is there anyone who knows how can I get all the variable values with one command?
print_r($_GET) will display all variables and if you like to loop the array use foreach ($_GET AS $key => $value) { echo $key . ' has the value ' . value . '<br />'; }
I've never heard of extract but it sounds pretty cool. I wonder what the security implications are, if any? Recently I've turned off REGISTER_GLOBALS because of possible problems. extract feels a little like it might have the same problems.
Actually there is no security implications, if you use the second and third parameter: extract($_GET, EXTR_PREFIX_ALL, 'safe_get'); PHP: this way you will access your variables in the query http://somwdomain.com/?id=5&action=view like $safe_get_id , $safe_get_action
I've learned not to screw around with any of that stuff both for security and efficiency later on in the code. I create an array of variables I expect to work with in the beginning like so. $svars = array( 'one' => '', 'two' => ''. 'three' => '' ); Code (markup): After that, I can loop through the array to gather information I want to use. I can conditionally set further variables which I check for using "isset" in other areas. I can unset certain indexes and pass the array to my PDO prepared statements. I can remove certain indexes and pass the array to my template class so that collected values can be re-inserted into the HTML form. It may seem like a lot of extra work at first, but once you get used to writing entire applications using newer PHP features you start to see how much less work it actually is. I'll probably look into using a "request" namespace instead of an array once PHP6 calms down a little.
I agree, that is great method. I used it when it came to have ability to have the "back" button while submitting POST form. It works great. But it is really too much pain to edit all these arrays when some variable is added or deleted in the form.