justinh Posted December 28, 2014 Share Posted December 28, 2014 (edited) Hi, I have a server-side PHP script to enumerate all the values in a form submission. After these values are processed, they are pushed to another script for another purpose. Some name/value pairs are required for secondary processing and some I don't care about. I want to know how to remove the names I don't care about for the secondary processing. Here is the code: <?php $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET") { $query_vars = $_GET; } elseif ($request_method == "POST") { $query_vars = $_POST; } reset($query_vars); $t = date("U"); $file = $_SERVER['DOCUMENT_ROOT'] . "ssfmgdform_" . $t; $fp = fopen($file,"w"); while (list ($key, $val) = each ($query_vars)) { fputs($fp,"<GDFORM_VARIABLE NAME=$key START>rn"); fputs($fp,"$valrn"); fputs($fp,"<GDFORM_VARIABLE NAME=$key END>rn"); if ($key == "redirect") { $landing_page = $val; } } fclose($fp); if ($landing_page != "") { header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); }?> So, if I know the name ($key) I'm interested in, can I inject something like 'if $key="XYZ", skip it' so it doesn't get processed downstream? By the time I get to this point, there is a name I don't need and don't want to process. I can barely walk around in this code, so I need to be spoon fed a bit. :-) Thanks, Justin Edited December 28, 2014 by justinh Link to comment Share on other sites More sharing options...
davej Posted December 28, 2014 Share Posted December 28, 2014 You might consider a switch-case statement. You can specify the keys that you want or the keys that you don't want. http://www.w3schools.com/php/php_switch.asp Link to comment Share on other sites More sharing options...
justinh Posted January 2, 2015 Author Share Posted January 2, 2015 I fixed it by adding this to the beginning of the while loop: unset($query_vars['unwanted value']); Link to comment Share on other sites More sharing options...
davej Posted January 2, 2015 Share Posted January 2, 2015 Hmmm... quite elegant. I tend to copy things rather than modifying things. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now