🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to save HTTP requests headers, methods and body to a file?

Method 1 – Using mod_log_forensic apache Module

Step 1 – Check if mod_log_forensic module is enabled or not

$ ./httpd -M | grep mod_log_forensic

Step 2 – Enable mod_log_forensic module using following lines in httpd.conf

LoadModule log_forensic_module /usr/lib64/httpd/modules/mod_log_forensic.so
<IfModule log_forensic_module>
ForensicLog /opt/lampp/logs/forensic_log
</IfModule>

Method 2 – Using PHP Script

$ grep -o 'account id: [^ ]\+' dumprequest.txt | sort | uniq -c
993 account id: 2919295
496 account id: 2956515
99 account id: 2956534
989 account id: 2984338
494 account id: 2984644
495 account id: 2984661
GET / HTTP/1.1
HTTP headers:
Host: www.devopsschool.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
Dnt: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
X-Newrelic-Synthetics: PwcbU19bDAADXE1AVQZUBFRTUwJPBAZSBE8MWg8IGVACUQxMAQMHVwFXUgcAWlwAEkhDVlQDUlRTUwYeAVFSVx1WDAMMFQxUAAcUVwNSBVJVVw9U
BFsJERxGAlIEAlFeXQEbAQdRVE8EVQ9RFVlXAQRICFVSWAIAUAYDVlAFGm4=
X-Abuse-Info: Request sent by a New Relic Synthetics Monitor (https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/administra
tion/identify-synthetics-requests-your-app) - monitor id: c033f890-2e77-4773-ac37-14c91b40476f | account id: 2984338
Request body:
GET / HTTP/1.1
<?php
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$_SERVER['SERVER_PROTOCOL']
);
foreach ($this->getHeaderList() as $name => $value) {
$data .= $name . ': ' . $value . "\n";
}
$data .= "\nRequest body:\n";
file_put_contents(
$targetFile,
$data . file_get_contents('php://input') . "\n*************************************************************\n", FILE_APPEND
);
echo("Done!\n\n");
}
private function getHeaderList() {
$headerList = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/',$name)) {
// convert HTTP_HEADER_NAME to Header-Name
$name = strtr(substr($name,5),'_',' ');
$name = ucwords(strtolower($name));
$name = strtr($name,' ','-');
// add to list
$headerList[$name] = $value;
}
}
return $headerList;
}
}
(new DumpHTTPRequestToFile)->execute('./dumprequest.txt');

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.