Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - How to access post variables ($_POST is empty)

Tags:

json

post

php

I'm working on a system and currently try to implement a script that another (external) system can post to some data so I can store them.
I have no control over the external system - I can just trigger it to post data to my system, giving it my script's url.

Looking at firebug when the post happens, I can see the data posted, something that looks like this:enter image description here

or (urldecoded)

content={"sex":"male","person":{"name":["chris"],"mbox":["mailto:[email protected]"]}}  
&Content-Type=application/json  
&auth=DDE233H76BGN

My problem is that when trying to get these parameters in my script, $_POST (and $_REQUEST) is always empty!
I've tried var_dump($_POST) or echo file_get_contents("php://input");, but I don't see any contents.

What am I missing here?
I don't know if response/request headers are needed to get something out of it, I show them here just in case
enter image description here

Edit:
My script now consists of a single line of code, like:

<?php
    var_dump($_POST);
?>

or

<?php
   echo file_get_contents("php://input");
?>

both of them give me absolutelly nothing :s

like image 638
CdB Avatar asked Nov 13 '22 17:11

CdB


1 Answers

The data should be accessed using $arr= json_decode($_POST['content']); ... but you have another problem here.

A detail is missing:

... how can firebug can show you the content of a $_POST that is sent from an external system to your website ( aka: the request does not go through your browser, but probably through an CURL request originating from the external server ). Obviously, I don't get something here.

What I see is a POST request sent from your browser ( in javascript ), made by your website. Your question miss a crucial detail, I'm just not sure what it is.

Hint:

Try to put an echo 'test'; just before your var_dump, I have the feeling that you may not be debugging the page that is really called by the Ajax POST request that we see in Firebug. A little routing problem ?

like image 82
FMaz008 Avatar answered Nov 15 '22 06:11

FMaz008