0

In particular, I am interested in viewing the 3 main types of data routinely sent to PHP, and available in the $_GET, $_POST and $_COOKIE arrays.

I’m not very conversant with HTTP, but as far as I am aware, the data sent from a form (method=post or get), a URL query string, or in cookies, is put into the HTTP headers and then sent to the server. (I’m not entirely sure whether that’s the case for method=post). It is, for the most part, in plain text.

The question is, how can I view this HTTP content in its raw form?

I am interested mainly to get a better understanding of the process.

Manngo
  • 14,066
  • 10
  • 88
  • 110
  • 2
    use chrome developer tools, with it you can inspect http headers. https://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome – ImAtWar May 31 '17 at 07:14
  • No, that information is not sent within HTTP headers. GET data goes in the **URL** and POST data goes in the request **body**. Hit F12 in your browser and you'll possibly open the developer tools. – Álvaro González May 31 '17 at 07:41
  • @ImAtWar Contrary to popular believe, Chrome is not the only browser that exists. All Most modern major browsers (including Microsoft's) include such a tool ;-P – Álvaro González May 31 '17 at 07:43
  • @ÁlvaroGonzález you mean vivaldi, safari, firefox, edge, internet-explorer opera? Lynx? – ImAtWar May 31 '17 at 07:44
  • @ImAtWar Internet Explorer is not modern. You probably caught me with Lynx, though :) – Álvaro González May 31 '17 at 07:47
  • @ÁlvaroGonzález I used Firefox developer tools, and, indeed, I see that what you say makes sense. Just to confirm, the `GET` data never actually appears inside the message header or body — just on the URL itself? – Manngo May 31 '17 at 07:47
  • @Manngo That's it. – Álvaro González May 31 '17 at 07:48
  • @ÁlvaroGonzález That information was exactly what I needed, although I also wanted to see this data in the flesh. Would you mind putting that in an answer so that I can accept it? – Manngo May 31 '17 at 07:50

3 Answers3

0

You can try $requestBody = file_get_contents('php://input'); I think this can help you.

Vahe Galstyan
  • 1,681
  • 1
  • 12
  • 25
0

As all $_GET,$_POST and $_COOKIE are arrays you can aslo do print_r to view the content in raw form.

print_r($_GET);
print_r($_POST);
print_r($_COOKIE);
Webdev
  • 617
  • 6
  • 24
0

The only piece of data that ends up in some PHP superglobal that's transmitted in HTTP headers are cookies. Such cookies often include the session ID used by sessions. $_GET gets populated from the URL:

An associative array of variables passed to the current script via the URL parameters

$_POST gets populated from the request body of HTTP request that use POST method, as long as they are formatted using one of the two formats implemented:

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

In both cases, you need to understand that they are convenience methods that work when you follow certain guidelines. Not all raw information is usable this way.

As per the way to inspect raw data, all decent major browsers nowadays include developer tools with a Network pane. Such tools are often mapped to the F12 keyboard short-cut. In the PHP side, you can inspect part of the raw URL with var_dump($_SERVER['REQUEST_URI']) (this variable won't include the protocol prefix, host name or port) and you can inspect raw POST body with e.g. var_dump(file_get_contents("php://input")).

Álvaro González
  • 142,137
  • 41
  • 261
  • 360