user1082428
user1082428

Reputation: 1081

PHP Post variable has duplicate, munged data

I was working on a simple link that would initiate an ajax call. This worked as expected until our Ubuntu server got decommissioned; we have a new, 'identical' server. The problem occurs on the server side, when I examine what is in POST. Expected echo of $_POST["scan_date"] is: 2012-11-26

Actual echo is: 2012-11-26scan_date=2012-11-26

And this is the actual echo in the PHP code below. The client side alert gives this: 2012-11-26 and that is what i expect. So, it appears that something is happening on the server side. I expect the echo to be "2012-11-26" and not "2012-11-26scan_date=2012-11-26"

I can't figure out why the POST data is getting munged up like that.

PHP:

$date = isset($_POST["scan_date"]) ? $_POST["scan_date"] : date("Y-m-d");
echo $date;  //produces 2012-11-26scan_date=2012-11-26 which is bad

JQuery:

var val = $(this).attr('value');
dateSelected = val.replace(/facterOption-/g, "");
dateSelected = $.trim(dateSelected);
alert(dateSelected);  //alerts 2012-11-26 which is good

$.ajax({
type: "POST",
dataType: 'json',
url: 'https://someurl',
data: {
scan_date: dateSelected
}
})

UPDATE: We have tried command line curl calls that were completely outside of the code framework for this PHP project, and the same result is being noticed. So maybe Apache has something to do with this.

Additionally, we discovered that adding a second POST parameter and value took care of this.

Upvotes: 2

Views: 653

Answers (3)

KingKongFrog
KingKongFrog

Reputation: 14429

This is an existing bug.

https://bugs.php.net/bug.php?id=22773

Solution is to:

  • Send another dummy name/value pair into the post
  • require > IE6
  • Use GET instead of POST if applicable

Upvotes: 1

valentinas
valentinas

Reputation: 4337

Chrome developer tools network tab or Firebug for Firefox will help you to debug the requests. Take a look at the request that is being sent. It is unlikely that there's something in PHP that would append stuff to your request. Most likely it's in JavaScript.

Upvotes: 1

cssyphus
cssyphus

Reputation: 40076

In your PHP file, try changing:

echo $date;

to

echo $_POST["scan_date"];

just to see what the PHP file is receiving.

Upvotes: 1

Related Questions