Skip to content

Instantly share code, notes, and snippets.

@erdum
Created October 3, 2023 08:00
Show Gist options
  • Save erdum/d368a38a61461f15f7dc96839fba8665 to your computer and use it in GitHub Desktop.
Save erdum/d368a38a61461f15f7dc96839fba8665 to your computer and use it in GitHub Desktop.
Get insight of the incoming http requests
<?php
$request_payload = !empty($_POST) ? $_POST : array();
$request_payload = empty($_POST) && !empty($_GET) ? $_GET : $request_payload;
$request_payload = isset($_SERVER['CONTENT_TYPE'])
&& $_SERVER['CONTENT_TYPE'] == 'application/json'
? json_decode(file_get_contents('php://input'), true)
: $request_payload;
$request_details = array(
'Request Method' => $_SERVER['REQUEST_METHOD'],
'Content-Type' => $_SERVER['CONTENT_TYPE'],
'Request Payload' => $request_payload,
'Accepted Content-Type' => $_SERVER['HTTP_ACCEPT'],
'Request Timestamp' => date('r', $_SERVER['REQUEST_TIME']),
'Client IP' => $_SERVER['REMOTE_ADDR'],
'Server IP' => $_SERVER['SERVER_ADDR'],
'Server Port' => $_SERVER['SERVER_PORT'],
'Https' => $_SERVER['HTTPS']
);
$content = '<h1>Test Results</h1><h3>request-tester.php</h3>';
$content .= '<pre>' . print_r($request_details, true) . '</pre>';
header("HTTP/1.1 200");
exit($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment