PHP getting the POST data

Hi! I have recently started using php for my web projects, and tried to use codea to post some data to my database, however, I have heard that Codea sends the raw data, not the $_POST data. I was wondering if anyone knows how to convert the raw data into the $_POST format.

Thanks,

Prynok

@HyroVitalyProtago Sorry it took me so long to get back, was at swim practice.

I tried both of those methods, to my avail nothing worked. Is there a certain place I need to send the data?

Thanks!

That remind me a discussion a long time ago : http://codea.io/talk/discussion/3223/need-help-http-request-post-solved

Ok, can you explain again exactly what is your problem ? You receive informations in $HTTP_RAW_POST_DATA but you want to convert them in a array, right ?

What works (a long time ago) for me :

Codea:

function setup()
   http.request(url, r, f, {
      method="POST",
      data=json.encode({foo="bar", bar="foo"})
   })
end

Php:

$array = json_decode($HTTP_RAW_POST_DATA);
var_dump($array);

EDIT: Sorry, forgot to post the code:

Codea Code:

function setup()
http.request("http://102.168.1.2/codea/php.php",r,f,{method="POST",data={["name"]="text"})
end

function r()
    print("connected")
 end

function f(error)
    print(error)
 end

Php code:

<?php
var_dump($HTTP_RAW_POST_DATA);

?>

@Prynok could you explain what is this adress in your code?
thanks!

@Jmv38 The address is my inner ip, since I didn’t port forward it though, Nothing outside of my network can view the webpage.

I think this is what you want : $HTTP_RAW_POST_DATA :wink:

@HyroVitalyProtago I think that is what I’m doing in the vardump, correct? Or do I put this in the codea method?

Thanks!

Sorry, I hasn’t view it x)

So, first possibility is to send in codea with json.encode(table) and recover it in PHP with json_decode($HTTP_RAW_POST_DATA).

Else, more simpler, in PHP :

parse_str($HTTP_RAW_POST_DATA, $array);
var_dump($array); 

I think that could work.