Convert postvars to querystring

A handy function that converts all variables in the $_POST array into a querystring. Useable if you wish to return to the form from which you posted and have access to all the submited values.

PHP:
  1. function postvarsToQueryString($postvars) {
  2.   $querystring='';
  3.   $keys = array_keys($postvars);
  4.   $values = array_values($postvars);
  5.   for ($i=0;$i<count($values); $i++) {
  6.     $querystring .= '&'.$keys[$i].'='.$values[$i];
  7.   }
  8.   return $querystring;
  9. }
  10.  
  11. $querystring = postvarsToQueryString($_POST);
  12. header("Location: myform.php?$querystring");

Leave a Reply

You must be logged in to post a comment.