?
Solved

Display $_POST value as querystring

Posted on 2005-03-03
4
Medium Priority
?
440 Views
Last Modified: 2006-11-17

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
Comment
Question by:invizabul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13453840
Try

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

Accepted Solution

by:
Batalf earned 200 total points
ID: 13453846
or

$string = "";
if(isset($_POST)){
  foreach($_POST as $Key=>$Value)
  {
      if(empty($string))$string="?"; else $string.="&";
      $string.="$Key=$Value";
  }
}
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 13454135
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
 
LVL 32

Expert Comment

by:Batalf
ID: 13454158
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question