[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Display $_POST value as querystring


I want to take the contents of the $_POST array and store it in a logfile in a querystring format (ie: ?fname=joe&lname=smith&id=12345) what is the easiest way to convert $_POST to this format?  is there a function that can do this?
0
invizabul
Asked:
invizabul
  • 3
1 Solution
 
BatalfCommented:
Try

$string = "";
if($_POST){
  foreach($_POST as $Key=>$Value)
  {
      if(!$string)$string="?"; else $string.="&";
      $string.="$Key=$Value";
  }
}
0
 
BatalfCommented:
or

$string = "";
if(isset($_POST)){
  foreach($_POST as $Key=>$Value)
  {
      if(empty($string))$string="?"; else $string.="&";
      $string.="$Key=$Value";
  }
}
0
 
ZhaawZSoftware DeveloperCommented:
You could also make a form with method 'get' (not 'post') and then just save $_SERVER['QUERY_STRING'], because everything that`s in the $_POST array will be visible as query string.

<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
0
 
BatalfCommented:
Yes, that's a solution. But if the purpose is only to store it into logfile, then it's much more reliable to continue using POST. For instance to avoid the data limit in GET.

Batalf
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now