[PHP] Problem receiving POSTed data
Hi everyone, So, I'm trying to receive POSTed data which is being sent from Flash structured as a nested array pictured (conceptually): id contains (a, b, c) a contains (prop1 = a1, prop2 = a2, ...) b contains (prop1 = b1, prop2 = b2, ...) c contains (prop1 = c1, prop2 = c2, ...) where a1, a2, b1, b2, c1, c2 are values stored in the keys prop1, prop2 etc. of their respective arrays. That's the conceptual structure, but that isn't how the information is passed to PHP from Flash. In Flash (which uses . notation for arrays), the data is packaged with a LoadVars object (for those who care) as follows: postObject.id1 postObject.id1.prop1 = a1 postObject.id1.prop2 = a2 ... postObject.id2.prop1 = b1 postObject.id2.prop2 = b2 ... etc. I *think* this data *should be* received by PHP (with dots converted to _ since that's what I've read php does) in the $_POST array as follows: $_POST contains (id1 - a, id1_prop1 - a1, id1_prop2 - a2, ..., id2 - b, id2_prop1 - b1, id2_prop2 - b2, ...) However, that's not what I appear to be getting from the $_POST array. When I run this code: /*/ $data = $_POST; $stuff = \n \n Post contains:; foreach($data as $prop = $val) { $stuff .= \n {$prop}: {$val}; } /*/ and write $stuff to a .txt file, I get the following output: Post contains: id1: a id2: b id3: c and that's it! No information at all about id1_prop1, id1_prop2, id2_prop1, etc etc. I am really stuck at this point. Does anyone know how multidimensional information is passed to the $_POST variable? I know it can be done with HTML forms and arrays, but I'm using flash and so I think my multidimensional array of information simply gets flattened into a one-dimensional array when POSTed as a described above (since Flash uses dot notation for arrays and php changes dots to underscores and just makes it one long variable name). And that would work fine if that's what it was doing, but, for some reason, $_POST doesn't seem to be receiving the second array dimension at all which contains all of my property information (which should have been flattened into the first dimension). If that's doesn't make any sense please let me know and I will attempt to clarify. Otherwise, any and all help is very much appreciated! Andy
Re: [PHP] Problem receiving POSTed data
Hang on - my php code may be working fine. It might be a problem with my actionscript code - particularly that the LoadVars object I'm using to send the data might not be able to take multidimensional data (though it definitely does not say that *anywhere* in the documentation!!). Stupid actionscript documentation. Raphael, here is the code I am using (I am iterating through all of the movieclips in my flash doc and gathering data on their name and position): /*/ for(var i in _level0) { if(typeof(_level0[i]) == movieclip) { data_lv[i] = _level0[i]; data_lv[i].id = _level0[i]._name; data_lv[i].x = _level0[i]._x; data_lv[i].y = _level0[i]._y; } } data_lv.sendAndLoad(myScript.php, data_lv, POST); /**/ The odd thing is that I print out the contents of data_lv and everything is there as expected in multidimensional form so I thought that was working fine, but someone on a flash message board just posted saying they thought LoadVars objects could not handle multidimensional data. So maybe even though the contents of the object print as expected, it doesn't send as expected. I'll try this in a completely one-dimensional array from flash to php and see if it works. If it does, I'll let everyone know. Andy On 10/6/06, Raphael Martins [EMAIL PROTECTED] wrote: Did you explicitly checked if the id1 'a' prop isn´t an array? Can you post your ActionScript codemaybe it´ll help! :D Good Luck 2006/10/6, Andy Hultgren [EMAIL PROTECTED]: Hi everyone, So, I'm trying to receive POSTed data which is being sent from Flash structured as a nested array pictured (conceptually): id contains (a, b, c) a contains (prop1 = a1, prop2 = a2, ...) b contains (prop1 = b1, prop2 = b2, ...) c contains (prop1 = c1, prop2 = c2, ...) where a1, a2, b1, b2, c1, c2 are values stored in the keys prop1, prop2 etc. of their respective arrays. That's the conceptual structure, but that isn't how the information is passed to PHP from Flash. In Flash (which uses . notation for arrays), the data is packaged with a LoadVars object (for those who care) as follows: postObject.id1 postObject.id1.prop1 = a1 postObject.id1.prop2 = a2 ... postObject.id2.prop1 = b1 postObject.id2.prop2 = b2 ... etc. I *think* this data *should be* received by PHP (with dots converted to _ since that's what I've read php does) in the $_POST array as follows: $_POST contains (id1 - a, id1_prop1 - a1, id1_prop2 - a2, ..., id2 - b, id2_prop1 - b1, id2_prop2 - b2, ...) However, that's not what I appear to be getting from the $_POST array. When I run this code: /*/ $data = $_POST; $stuff = \n \n Post contains:; foreach($data as $prop = $val) { $stuff .= \n {$prop}: {$val}; } /*/ and write $stuff to a .txt file, I get the following output: Post contains: id1: a id2: b id3: c and that's it! No information at all about id1_prop1, id1_prop2, id2_prop1, etc etc. I am really stuck at this point. Does anyone know how multidimensional information is passed to the $_POST variable? I know it can be done with HTML forms and arrays, but I'm using flash and so I think my multidimensional array of information simply gets flattened into a one-dimensional array when POSTed as a described above (since Flash uses dot notation for arrays and php changes dots to underscores and just makes it one long variable name). And that would work fine if that's what it was doing, but, for some reason, $_POST doesn't seem to be receiving the second array dimension at all which contains all of my property information (which should have been flattened into the first dimension). If that's doesn't make any sense please let me know and I will attempt to clarify. Otherwise, any and all help is very much appreciated! Andy
Re: [PHP] Problem receiving POSTed data
On Fri, October 6, 2006 4:01 pm, Andy Hultgren wrote: /*/ $data = $_POST; $stuff = \n \n Post contains:; foreach($data as $prop = $val) { $stuff .= \n {$prop}: {$val}; } /*/ pre?php var_dump($_POST);?/pre PHP does pretty minimal munging of the POST data. It's unlikely that Flash is sending what you think it's sending. Even if it is, you have two options: 1. Use HTTP_RAW_POST_DATA (turn it on in PHP) and write your own Flash array parser in PHP. 2. Convince Flash to POST data more like PHP wants it: id[a][prop1]=a1id[a][prop2]=a2id[b][prop1]=b1... #2 will probably be WAY easier, unless Flash is even more broken than I think. And I think Flash is pretty broken. :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem receiving POSTed data
Am working on #2 right now... On 10/6/06, Richard Lynch [EMAIL PROTECTED] wrote: On Fri, October 6, 2006 4:01 pm, Andy Hultgren wrote: /*/ $data = $_POST; $stuff = \n \n Post contains:; foreach($data as $prop = $val) { $stuff .= \n {$prop}: {$val}; } /*/ pre?php var_dump($_POST);?/pre PHP does pretty minimal munging of the POST data. It's unlikely that Flash is sending what you think it's sending. Even if it is, you have two options: 1. Use HTTP_RAW_POST_DATA (turn it on in PHP) and write your own Flash array parser in PHP. 2. Convince Flash to POST data more like PHP wants it: id[a][prop1]=a1id[a][prop2]=a2id[b][prop1]=b1... #2 will probably be WAY easier, unless Flash is even more broken than I think. And I think Flash is pretty broken. :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?
Re: [PHP] Problem receiving POSTed data
Problem solved: it was indeed that the flash object did not like multidimensional data. I didn't change my PHP code one little bit. But I changed my my ActionScript code to write the data in a 1-dimensional form as follows: /*/ for(var i in _level0) { if(typeof(_level0[i]) == movieclip) { data_lv[i + _path] = _level0[i]; data_lv[i + _id] = _level0[i]._name; data_lv[i + _x] = _level0[i]._x; data_lv[i + _y] = _level0[i]._y; } } data_lv.sendAndLoad(myScript.php, data_lv, POST); /**/ This works perfectly and php receives all of the data correctly. Thanks guys for your thoughts. I'm going to be posting an addition to the online ActionScript documentation to hopefully help others avoid this pitfall! Andy On 10/6/06, Andy Hultgren [EMAIL PROTECTED] wrote: Am working on #2 right now... On 10/6/06, Richard Lynch [EMAIL PROTECTED] wrote: On Fri, October 6, 2006 4:01 pm, Andy Hultgren wrote: /*/ $data = $_POST; $stuff = \n \n Post contains:; foreach($data as $prop = $val) { $stuff .= \n {$prop}: {$val}; } /*/ pre?php var_dump($_POST);?/pre PHP does pretty minimal munging of the POST data. It's unlikely that Flash is sending what you think it's sending. Even if it is, you have two options: 1. Use HTTP_RAW_POST_DATA (turn it on in PHP) and write your own Flash array parser in PHP. 2. Convince Flash to POST data more like PHP wants it: id[a][prop1]=a1id[a][prop2]=a2id[b][prop1]=b1... #2 will probably be WAY easier, unless Flash is even more broken than I think. And I think Flash is pretty broken. :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?