Checking the data type received in POST in PHP

3

I need to find out what kind of data I am getting in a user's post. The user can provide me the data in XML format, JSON HTML and text Content-Type = text / xml / json / text / html Accept = application / json / xml / text / html

    
asked by anonymous 07.07.2016 / 15:01

1 answer

3

To check the content-type of a post request you can do:

$_SERVER["CONTENT_TYPE"];

To see the headers of the server response you can do:

print_r(get_headers('http://pt.stackoverflow.com/questions/139310/verificando-o-tipo-de-dados-recebido-no-post-em-php'));

Output in this case:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Cache-Control: public, max-age=60
    [2] => Content-Type: text/html; charset=utf-8
    [3] => Expires: Thu, 07 Jul 2016 13:21:56 GMT
    [4] => Last-Modified: Thu, 07 Jul 2016 13:20:56 GMT
    [5] => X-Frame-Options: SAMEORIGIN
    [6] => X-Request-Guid: 79b68547-ba8b-40fc-973f-fff0e2286f7d
    [7] => Content-Length: 53578
    [8] => Accept-Ranges: bytes
    [9] => Date: Thu, 07 Jul 2016 13:20:56 GMT
    [10] => Via: 1.1 varnish
    [11] => Age: 0
    [12] => Connection: close
    [13] => X-Served-By: cache-fra1230-FRA
    [14] => X-Cache: MISS
    [15] => X-Cache-Hits: 0
    [16] => X-Timer: S1467897656.395677,VS0,VE99
    [17] => Vary: *
    [18] => X-DNS-Prefetch-Control: off
    [19] => Set-Cookie: prov=1c178290-fa4b-4210-c876-98a0cddcbc11; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
)

Among them is Content-Type

    
07.07.2016 / 15:21