Jump to content

Getting data from "Content-type: form-data;" type post


Recommended Posts

(I realized I had posted this in the wrong place at first and requested that the other one be closed)

I have been fiddling with this for 2 days and still cannot get the data to dump to a variable or array.

I am trying to get data from this post data into a variable:

 

POST /highscore HTTP/1.1

Host: trials02.ifap4u.com:80

User-Agent: Test 2 (WIN32)

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Connection: close

Content-Type: multipart/form-data; boundary=---------------------------1641204588873

Content-Length: 2270

 

-----------------------------1641204588873

Content-Disposition: form-data; name="track"

 

12968487

-----------------------------1641204588873

Content-Disposition: form-data; name="faults"

 

0

-----------------------------1641204588873

Content-Disposition: form-data; name="time"

 

1803

-----------------------------1641204588873

Content-Disposition: form-data; name="name"

 

test

-----------------------------1641204588873

Content-Disposition: form-data; name="key"

 

XXXXX-XXXXX

-----------------------------1641204588873

Content-Disposition: form-data; name="pcid"

 

-0000000000

-----------------------------1641204588873

Content-Disposition: form-data; name="version"

 

3867393

-----------------------------1641204588873

Content-Disposition: form-data; name="build"

 

27

-----------------------------1641204588873

Content-Disposition: form-data; name="recording"; filename="100binary"

Content-Type: application/octe

Posted data automatically ends up in the $_POST array while uploaded files will be within the $_FILES array.

 

Is this what your looking for? Your question, or lack there of, is pretty vague.

I have tried the basic methods for getting POST data but all of them have turned up nothing.

 

Sorry, I am extremely tired. I can get data from basic POST's but I cannot get data for posts using "Content-Disposition".

Its still not clear exactly what your trying to do.

Let me try one more time:

I have a game that posts score data to a script with the multipart/form-data ENCTYPE, but I cannot get my php script to parse the data that was posted to it.

So I am looking for help on how to accomplish this in my php script. I cannot change how the game posts the data though.

As of now, this is what I have:

<?
$data = file_get_contents("php://input");
$fh = fopen("data.txt", 'w') or die();
fwrite($fh, $data);
fclose($fh);
$cmd = $_GET['cmd'];
if($cmd == "registername"){
echo "OK";
}else{
echo $data;
}
?>

I have it write the output of it's operations to "data.txt" so that I can view the posted data from the game.

yeah...php should automatically parse it and store it in $_POST

 

Try this and see what get's stored in data.txt:

 

 

<?php
$data = file_get_contents("php://input");
$fh = fopen("data.txt", 'w') or die();
//fwrite($fh, $data);
fwrite($fh,var_export($_POST,true));
fclose($fh);
$cmd = $_GET['cmd'];
if($cmd == "registername"){
echo "OK";
}else{
echo $data;
}
?>

Ok, so youve got the data that was posted into a text file. What do you want to parse out of it? And what exactly do you want to do with this data?

I want to get the value of "track" out of this part of the data for example:

-----------------------------1641204588873
Content-Disposition: form-data; name="track"

12968487

The value would be "12968487".

 

I just want it to go to a variable and then I have already written a script to write it to a database.

Replace your current script with...

 

<?php

  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $var = $_POST['track'];
  }

  // $var now contains 12968487 re your example.

?>

As rhodesa said, I have already tried dumping all post data.

Have you tried to see the HTTP headers that are being sent to your script. Try capturing them using the Firefox plug-in Live HTTP Headers. Maybe there are errors being generated which you're not seeing and are causing your script not to get anything.

 

Ken

Have you tried to see the HTTP headers that are being sent to your script. Try capturing them using the Firefox plug-in Live HTTP Headers. Maybe there are errors being generated which you're not seeing and are causing your script not to get anything.

 

Ken

Thanks for the advice, but it still didn't help. I have it setup in such a way that if any PHP errors showed up they are emailed to me as well as any data being pushed out just be sure that I don't miss anything.

The errors I'm talking about might be occurring before your script gets invoked, so you wouldn't see any PHP errors. If you've captured the HTTP headers, can you post them here?

 

Ken

Sure, I think these are what you're looking for, I'm not sure though:

POST /highscore HTTP/1.1
Host: trials02.ifap4u.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: __qca=1198818578-32245428-7908646
Cache-Control: max-age=0

HTTP/1.x 200 OK
Date: Sat, 02 Feb 2008 00:34:04 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.2.2
Content-Length: 0
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/html

If those are the entire headers, then there's the problem... The first header which is the POST header is showing no data being posted.

 

Ken

Those are, I just used a blank post statement. I cannot capture the actual data because it is being posted via winsock in a game. As for those, all I have is the headers from page 1.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.