Complete XAMPP POST Request Logging Setup Guide
Step 1: Install and Start XAMPP
Installation:
Run XAMPP installer you downloaded
Choose installation directory (default:
C:\xampp\)Select components: Make sure Apache and PHP are checked
Complete installation
Start Services:
Open XAMPP Control Panel (as Administrator)
Start Apache - Click "Start" button next to Apache
Start MySQL (optional, but good to have)
Verify: Apache should show "Running" in green
Test Installation:
Open browser and go to
http://localhostYou should see XAMPP dashboard
Step 2: Locate XAMPP Files
Important XAMPP directories:
Installation folder:
C:\xampp\Apache config:
C:\xampp\apache\conf\httpd.confWebsite files:
C:\xampp\htdocs\Log files:
C:\xampp\apache\logs\
Step 3: Configure Apache for POST Logging
File to Edit: C:\xampp\apache\conf\httpd.conf
Open httpd.conf file:
Navigate to
C:\xampp\apache\conf\Right-click
httpd.confSelect "Open with" โ "Notepad" (or any text editor)
Important: Run as Administrator if prompted
Find and verify these modules are enabled (should already be uncommented in XAMPP):
apacheLoadModule rewrite_module modules/mod_rewrite.so
LoadModule log_config_module modules/mod_log_config.so
3 Add POST logging configuration at the END of httpd.conf file:
# ========== POST REQUEST LOGGING CONFIGURATION ==========
# Custom log format to capture POST requests with detailed info
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" post_detailed
# Log all requests to a custom file
CustomLog logs/all_requests.log post_detailed
# Log only POST requests
SetEnvIf Request_Method POST is_post_request
CustomLog logs/post_requests_only.log post_detailed env=is_post_request
# Enable detailed request/response logging
LoadModule dumpio_module modules/mod_dumpio.so
<IfModule mod_dumpio.c>
DumpIOInput On
DumpIOOutput On
LogLevel dumpio:trace7
</IfModule>
# Custom log location for our test
# Remove the CustomLog from Directory block - just keep this:
<Directory "C:/xampp/htdocs/posttest">
LogLevel info
</Directory>
# Move CustomLog outside (global level)
# For specific directory logging, we'll use virtual host or location instead
# ========== END POST LOGGING CONFIGURATION ==========
Step 4: Create Test Files(Here i will be creating my own pages so that i can test the POST logs)
I will be creating 6 files here.
๐ What Each File Does in Your POST Logger System
Core Files:
index.htmlMain frontend interface with different POST testing forms
Contains HTML forms, AJAX requests, and file upload tests
Entry point for your application
process.phpProcesses and logs all regular POST requests
Handles form data, JSON data, and AJAX requests
Logs detailed request information (headers, IP, content)
Writes to detailed_post_log.txt
upload.phpSpecialized handler for file uploads
Processes files submitted via POST
Validates uploads and handles errors
Logs file information to upload_log.txt
Utility Files:
log_viewer.phpWeb-based log viewer interface
Shows real-time logs with auto-refresh
Displays both detailed_post_log.txt and upload_log.txt
Has log clearing functionality and stats
test_connection.phpTroubleshooting tool to verify Apache connection
Shows server configuration and port information
Provides correct URLs based on your server setup
Quick access links to other pages
Log Files:
detailed_post_log.txtLog file containing POST request data
Created and written to by process.php
Contains timestamps, headers, and request content
This complete system lets us test, capture, log, and view different types of HTTP POST requests through your Apache server.
Now lets Create those all required Directory (called as posttest) :
Navigate to:
C:\xampp\htdocs\Create new folder:
posttestFull path:
C:\xampp\htdocs\posttest\
File 1: Create index.html
Location: C:\xampp\htdocs\posttest\index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>POST Request Testing</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
form { border: 1px solid #ccc; padding: 20px; margin: 20px 0; }
input, textarea { width: 300px; padding: 5px; margin: 5px 0; }
button { padding: 10px 20px; margin: 10px 5px; background: #007cba; color: white; border: none; cursor: pointer; }
button:hover { background: #005a87; }
.result { border: 1px solid #ddd; padding: 10px; margin: 10px 0; background: #f9f9f9; }
</style>
</head>
<body>
<h1>POST Request Logging Test</h1>
<div style="background: #e6f3ff; padding: 15px; border-radius: 8px; margin: 20px 0;">
<h3>๐ Debug Tools</h3>
<a href="log_viewer.php" style="display: inline-block; padding: 10px 15px; background: #28a745; color: white; text-decoration: none; border-radius: 5px; margin: 5px;">๐ View Logs</a>
<p style="margin: 10px 0 0 0; font-size: 14px; color: #666;">
Use the log viewer to see detailed POST request logs and debug any issues.
</p>
</div>
<!-- Form POST Test -->
<h2>1. HTML Form POST Test</h2>
<form action="process.php" method="POST">
<label>Username:</label><br>
<input type="text" name="username" value="testuser" required><br>
<label>Email:</label><br>
<input type="email" name="email" value="test@example.com" required><br>
<label>Password:</label><br>
<input type="password" name="password" value="secret123" required><br>
<label>Message:</label><br>
<textarea name="message" rows="4">This is a test POST message</textarea><br>
<button type="submit">Submit Form POST</button>
</form>
<!-- AJAX POST Test -->
<h2>2. AJAX POST Test</h2>
<button onclick="sendAjaxPost()">Send AJAX POST</button>
<button onclick="sendJsonPost()">Send JSON POST</button>
<div id="ajaxResult" class="result" style="display:none;">
<h3>AJAX Result:</h3>
<pre id="ajaxResponse"></pre>
</div>
<!-- File Upload POST Test -->
<h2>3. File Upload POST Test</h2>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<label>Select file:</label><br>
<input type="file" name="uploadfile"><br>
<input type="text" name="description" placeholder="File description"><br>
<button type="submit">Upload File</button>
</form>
<script>
function sendAjaxPost() {
const formData = new FormData();
formData.append('username', 'ajaxuser');
formData.append('email', 'ajax@example.com');
formData.append('action', 'ajax_test');
fetch('process.php', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(data => {
document.getElementById('ajaxResult').style.display = 'block';
document.getElementById('ajaxResponse').textContent = data;
})
.catch(error => {
console.error('Error:', error);
});
}
function sendJsonPost() {
const jsonData = {
username: 'jsonuser',
email: 'json@example.com',
message: 'This is JSON POST data',
timestamp: new Date().toISOString(),
data: {
nested: 'value',
array: [1, 2, 3]
}
};
fetch('process.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(jsonData)
})
.then(response => response.text())
.then(data => {
document.getElementById('ajaxResult').style.display = 'block';
document.getElementById('ajaxResponse').textContent = data;
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
</body>
</html>
File 2: Create process.php
Location: C:\xampp\htdocs\posttest\process.php
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set content type
header('Content-Type: text/plain; charset=utf-8');
// Log file path with proper error handling
$log_file = 'detailed_post_log.txt';
// Ensure log directory is writable
if (!is_writable(dirname($log_file))) {
echo "ERROR: Log directory is not writable\n";
exit(1);
}
// Get current timestamp
$timestamp = date('Y-m-d H:i:s');
// Start output
echo "=== POST Request Processed ===\n";
echo "Timestamp: $timestamp\n";
echo "Method: " . ($_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN') . "\n";
echo "Client IP: " . ($_SERVER['REMOTE_ADDR'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'UNKNOWN') . "\n";
echo "User Agent: " . ($_SERVER['HTTP_USER_AGENT'] ?? 'UNKNOWN') . "\n";
// Log entry for our custom log with safety checks
$log_entry = "\n" . str_repeat("=", 60) . "\n";
$log_entry .= "POST Request Log - $timestamp\n";
$log_entry .= "Client IP: " . ($_SERVER['REMOTE_ADDR'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'UNKNOWN') . "\n";
$log_entry .= "User Agent: " . ($_SERVER['HTTP_USER_AGENT'] ?? 'UNKNOWN') . "\n";
$log_entry .= "Request URI: " . ($_SERVER['REQUEST_URI'] ?? 'UNKNOWN') . "\n";
$log_entry .= "Server Name: " . ($_SERVER['SERVER_NAME'] ?? 'UNKNOWN') . "\n";
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
echo "\n--- POST DATA RECEIVED ---\n";
// Handle regular form data with improved security
if (!empty($_POST)) {
echo "\nForm Data:\n";
foreach ($_POST as $key => $value) {
// Limit log entry length to prevent log injection
$safe_key = substr(htmlspecialchars($key), 0, 100);
$safe_value = substr(htmlspecialchars($value), 0, 1000);
echo " $safe_key: $safe_value\n";
$log_entry .= "Form - $safe_key: " . addslashes($safe_value) . "\n";
}
}
// Handle file uploads with error checking
if (!empty($_FILES)) {
echo "\nFile Upload Data:\n";
foreach ($_FILES as $key => $file) {
$safe_key = htmlspecialchars($key);
$safe_name = htmlspecialchars($file['name'] ?? 'UNKNOWN');
$file_size = $file['size'] ?? 0;
$file_type = htmlspecialchars($file['type'] ?? 'UNKNOWN');
$upload_error = $file['error'] ?? UPLOAD_ERR_NO_FILE;
echo " File Field: $safe_key\n";
echo " File Name: $safe_name\n";
echo " File Size: $file_size bytes\n";
echo " File Type: $file_type\n";
echo " Upload Error Code: $upload_error\n";
$log_entry .= "File - $safe_key: $safe_name ($file_size bytes) [Error: $upload_error]\n";
}
}
// Handle JSON data with improved parsing
$json_input = file_get_contents('php://input');
if (!empty($json_input) && empty($_POST)) {
echo "\nRaw JSON Data (first 500 chars):\n";
echo substr($json_input, 0, 500) . (strlen($json_input) > 500 ? '...' : '') . "\n";
// Safely log JSON data (limit length)
$safe_json = substr($json_input, 0, 2000);
$log_entry .= "JSON Data: " . addslashes($safe_json) . "\n";
// Try to decode JSON with error handling
$decoded = json_decode($json_input, true);
if (json_last_error() === JSON_ERROR_NONE && $decoded) {
echo "\nDecoded JSON:\n";
foreach ($decoded as $key => $value) {
$safe_key = substr(htmlspecialchars($key), 0, 100);
if (is_array($value) || is_object($value)) {
$safe_value = substr(json_encode($value), 0, 500);
echo " $safe_key: $safe_value\n";
} else {
$safe_value = substr(htmlspecialchars($value), 0, 500);
echo " $safe_key: $safe_value\n";
}
}
} else {
echo "\nJSON Decode Error: " . json_last_error_msg() . "\n";
$log_entry .= "JSON Error: " . json_last_error_msg() . "\n";
}
}
// Log important headers (with safety checks)
echo "\n--- IMPORTANT REQUEST HEADERS ---\n";
$important_headers = ['Content-Type', 'Content-Length', 'Authorization', 'X-Requested-With', 'Referer', 'Origin'];
if (function_exists('getallheaders')) {
$headers = getallheaders();
if ($headers) {
foreach ($important_headers as $header_name) {
foreach ($headers as $name => $value) {
if (strcasecmp($name, $header_name) === 0) {
$safe_value = substr(htmlspecialchars($value), 0, 200);
echo "$name: $safe_value\n";
$log_entry .= "Header - $name: " . addslashes($safe_value) . "\n";
break;
}
}
}
}
} else {
echo "getallheaders() function not available\n";
// Fallback to $_SERVER
foreach ($important_headers as $header) {
$server_key = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
if (isset($_SERVER[$server_key])) {
$safe_value = substr(htmlspecialchars($_SERVER[$server_key]), 0, 200);
echo "$header: $safe_value\n";
$log_entry .= "Header - $header: " . addslashes($safe_value) . "\n";
}
}
}
} else {
echo "\nNot a POST request - Method: " . ($_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN') . "\n";
$log_entry .= "Non-POST request - Method: " . ($_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN') . "\n";
}
// Write to custom log file with error handling
$log_entry .= "End Time: " . date('Y-m-d H:i:s') . "\n";
$log_entry .= str_repeat("=", 60) . "\n";
$write_result = file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);
if ($write_result === false) {
echo "\nERROR: Could not write to log file: $log_file\n";
echo "Check file permissions and disk space\n";
} else {
echo "\nCustom log written successfully ($write_result bytes)\n";
}
echo "\n--- END OF RESPONSE ---\n";
echo "Apache access/error logs: C:\\xampp\\apache\\logs\\\n";
echo "Custom detailed log: " . realpath($log_file) . "\n";
echo "Log file size: " . (file_exists($log_file) ? filesize($log_file) . " bytes" : "File not found") . "\n";
?>
File 3: Create upload.php
Location: C:\xampp\htdocs\posttest\upload.php
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set content type
header('Content-Type: text/html; charset=utf-8');
echo "<h2>File Upload Result</h2>";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if file was uploaded
if (isset($_FILES['uploadfile']) && $_FILES['uploadfile']['error'] !== UPLOAD_ERR_NO_FILE) {
$file = $_FILES['uploadfile'];
echo "<p><strong>File Information:</strong></p>";
echo "<ul>";
echo "<li>Name: " . htmlspecialchars($file['name'] ?? 'UNKNOWN') . "</li>";
echo "<li>Size: " . ($file['size'] ?? 0) . " bytes</li>";
echo "<li>Type: " . htmlspecialchars($file['type'] ?? 'UNKNOWN') . "</li>";
echo "<li>Temp Name: " . htmlspecialchars($file['tmp_name'] ?? 'UNKNOWN') . "</li>";
echo "<li>Upload Error Code: " . ($file['error'] ?? 'UNKNOWN') . "</li>";
echo "</ul>";
// Check for upload errors
if ($file['error'] !== UPLOAD_ERR_OK) {
$error_messages = [
UPLOAD_ERR_INI_SIZE => 'File is larger than upload_max_filesize directive',
UPLOAD_ERR_FORM_SIZE => 'File is larger than MAX_FILE_SIZE directive',
UPLOAD_ERR_PARTIAL => 'File was only partially uploaded',
UPLOAD_ERR_NO_FILE => 'No file was uploaded',
UPLOAD_ERR_NO_TMP_DIR => 'Missing temporary folder',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension'
];
$error_msg = $error_messages[$file['error']] ?? 'Unknown upload error';
echo "<p style='color: red;'><strong>Upload Error:</strong> " . htmlspecialchars($error_msg) . "</p>";
} else {
echo "<p style='color: green;'><strong>Upload Status:</strong> File uploaded successfully to temporary location</p>";
// Basic file validation
$max_size = 10 * 1024 * 1024; // 10MB limit
if ($file['size'] > $max_size) {
echo "<p style='color: orange;'><strong>Warning:</strong> File is larger than 10MB</p>";
}
// Get file extension
$file_extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
echo "<li>File Extension: " . htmlspecialchars($file_extension) . "</li>";
}
// Handle description
if (isset($_POST['description']) && !empty(trim($_POST['description']))) {
$description = trim($_POST['description']);
echo "<p><strong>Description:</strong> " . htmlspecialchars($description) . "</p>";
} else {
$description = 'No description provided';
}
// Enhanced logging with more details
$timestamp = date('Y-m-d H:i:s');
$client_ip = $_SERVER['REMOTE_ADDR'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'UNKNOWN';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'UNKNOWN';
$log_entry = str_repeat("=", 50) . "\n";
$log_entry .= "File Upload Log - $timestamp\n";
$log_entry .= "Client IP: $client_ip\n";
$log_entry .= "User Agent: " . substr($user_agent, 0, 100) . "\n";
$log_entry .= "File Name: " . ($file['name'] ?? 'UNKNOWN') . "\n";
$log_entry .= "File Size: " . ($file['size'] ?? 0) . " bytes\n";
$log_entry .= "File Type: " . ($file['type'] ?? 'UNKNOWN') . "\n";
$log_entry .= "Upload Error: " . ($file['error'] ?? 'UNKNOWN') . "\n";
$log_entry .= "Description: " . addslashes($description) . "\n";
$log_entry .= str_repeat("=", 50) . "\n\n";
// Write to log file with error handling
$log_file = 'upload_log.txt';
$write_result = file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);
if ($write_result === false) {
echo "<p style='color: red;'>Error: Could not write to log file. Check file permissions.</p>";
} else {
echo "<p style='color: green;'>File upload logged successfully! ($write_result bytes written)</p>";
echo "<p><small>Log file: " . realpath($log_file) . "</small></p>";
}
} else {
echo "<p style='color: red;'>No file uploaded or upload error occurred.</p>";
// Log failed upload attempt
$timestamp = date('Y-m-d H:i:s');
$client_ip = $_SERVER['REMOTE_ADDR'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'UNKNOWN';
$error_code = $_FILES['uploadfile']['error'] ?? 'NO_FILE_INPUT';
$log_entry = "Failed Upload - $timestamp - IP: $client_ip - Error: $error_code\n";
file_put_contents('upload_log.txt', $log_entry, FILE_APPEND | LOCK_EX);
}
} else {
echo "<p style='color: orange;'>No POST data received. Please use the upload form.</p>";
}
echo "<p><a href='index.html'>โ Back to Tests</a></p>";
echo "<p><small>Current working directory: " . getcwd() . "</small></p>";
?>
File 4: Create test_connection.php
Location: C:\xampp\htdocs\posttest\test_connection.php
<?php
// Simple connection test script
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<title>XAMPP Connection Test</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; background: #f0f8ff; }
.success { background: #d4edda; color: #155724; padding: 15px; border-radius: 5px; border: 1px solid #c3e6cb; }
.info { background: #e2f3ff; color: #0c5460; padding: 15px; border-radius: 5px; border: 1px solid #bee5eb; }
.code { background: #f8f9fa; padding: 10px; font-family: monospace; border-radius: 4px; border: 1px solid #dee2e6; }
</style>
</head>
<body>
<h1>๐ XAMPP Connection Test - SUCCESS!</h1>
<div class="success">
<h2>โ
Apache is working!</h2>
<p><strong>If you can see this page, Apache is running correctly.</strong></p>
</div>
<div class="info">
<h3>๐ Connection Details</h3>
<p><strong>Server:</strong> <?php echo $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown'; ?></p>
<p><strong>Server Name:</strong> <?php echo $_SERVER['SERVER_NAME'] ?? 'Unknown'; ?></p>
<p><strong>Server Port:</strong> <?php echo $_SERVER['SERVER_PORT'] ?? 'Unknown'; ?></p>
<p><strong>Request URI:</strong> <?php echo $_SERVER['REQUEST_URI'] ?? 'Unknown'; ?></p>
<p><strong>Current URL:</strong> <?php echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?></p>
</div>
<div class="info">
<h3>๐ Correct URLs for Your POST Logger</h3>
<div class="code">
<p><strong>Main Test Page:</strong><br>
<a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/posttest/">http://<?php echo $_SERVER['HTTP_HOST']; ?>/posttest/</a></p>
<p><strong>Log Viewer:</strong><br>
<a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/posttest/log_viewer.php">http://<?php echo $_SERVER['HTTP_HOST']; ?>/posttest/log_viewer.php</a></p>
</div>
</div>
<div class="info">
<h3>โก Quick Actions</h3>
<p><a href="index.html" style="background: #007cba; color: white; padding: 10px 15px; text-decoration: none; border-radius: 5px;">Go to POST Tests</a></p>
<p><a href="log_viewer.php" style="background: #28a745; color: white; padding: 10px 15px; text-decoration: none; border-radius: 5px;">View Logs</a></p>
</div>
<div class="info">
<h3>๐ก Troubleshooting Tips</h3>
<ul>
<li>Make sure XAMPP Control Panel shows Apache as "Running" (green)</li>
<li>Check if any antivirus is blocking Apache</li>
<li>Verify port <?php echo $_SERVER['SERVER_PORT']; ?> is not blocked by Windows Firewall</li>
<li>If using a different port, always include it in the URL</li>
</ul>
</div>
</body>
</html>
File 5: Create logviewer.php
Location: C:\xampp\htdocs\posttest\logviewer.php
<?php
// Log Viewer for POST Request Debugging
// This script helps view the generated log files
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>POST Request Log Viewer</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.log-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
.log-content { background: #f8f8f8; padding: 15px; border-radius: 5px; max-height: 400px; overflow-y: auto; font-family: monospace; font-size: 12px; white-space: pre-wrap; }
.button { padding: 8px 15px; margin: 5px; background: #007cba; color: white; text-decoration: none; border-radius: 4px; display: inline-block; }
.button:hover { background: #005a87; }
.error { color: red; background: #ffe6e6; padding: 10px; border-radius: 5px; }
.success { color: green; background: #e6ffe6; padding: 10px; border-radius: 5px; }
.info { color: #666; font-size: 14px; }
.stats { background: #e6f3ff; padding: 10px; border-radius: 5px; margin: 10px 0; }
</style>
<script>
function autoRefresh() {
setTimeout(function(){ location.reload(); }, 5000);
}
function clearLogs(logFile) {
if (confirm('Are you sure you want to clear the ' + logFile + ' log?')) {
window.location.href = '?action=clear&log=' + logFile;
}
}
</script>
</head>
<body onload="autoRefresh()">
<div class="container">
<h1>๐ POST Request Log Viewer</h1>
<p class="info">This page auto-refreshes every 5 seconds to show the latest logs.</p>
<div style="margin: 20px 0;">
<a href="index.html" class="button">โ Back to Tests</a>
<a href="?refresh=1" class="button">๐ Refresh Now</a>
<button onclick="clearLogs('detailed')" class="button" style="background: #dc3545;">๐๏ธ Clear Detailed Log</button>
<button onclick="clearLogs('upload')" class="button" style="background: #dc3545;">๐๏ธ Clear Upload Log</button>
</div>
<?php
// Handle log clearing
if (isset($_GET['action']) && $_GET['action'] === 'clear' && isset($_GET['log'])) {
$log_to_clear = $_GET['log'];
if ($log_to_clear === 'detailed' && file_exists('detailed_post_log.txt')) {
if (file_put_contents('detailed_post_log.txt', '') !== false) {
echo '<div class="success">โ
Detailed POST log cleared successfully!</div>';
} else {
echo '<div class="error">โ Failed to clear detailed POST log.</div>';
}
} elseif ($log_to_clear === 'upload' && file_exists('upload_log.txt')) {
if (file_put_contents('upload_log.txt', '') !== false) {
echo '<div class="success">โ
Upload log cleared successfully!</div>';
} else {
echo '<div class="error">โ Failed to clear upload log.</div>';
}
}
}
// Display detailed POST log
echo '<div class="log-section">';
echo '<h2>๐ Detailed POST Log (detailed_post_log.txt)</h2>';
if (file_exists('detailed_post_log.txt')) {
$file_size = filesize('detailed_post_log.txt');
$last_modified = date('Y-m-d H:i:s', filemtime('detailed_post_log.txt'));
echo "<div class='stats'>";
echo "<strong>File Size:</strong> " . number_format($file_size) . " bytes<br>";
echo "<strong>Last Modified:</strong> $last_modified<br>";
echo "<strong>File Path:</strong> " . realpath('detailed_post_log.txt');
echo "</div>";
if ($file_size > 0) {
$content = file_get_contents('detailed_post_log.txt');
// Show last 5000 characters if file is too large
if (strlen($content) > 5000) {
$content = "...[File truncated - showing last 5000 characters]...\n\n" . substr($content, -5000);
}
echo '<div class="log-content">' . htmlspecialchars($content) . '</div>';
} else {
echo '<div class="info">๐ Log file is empty.</div>';
}
} else {
echo '<div class="error">โ detailed_post_log.txt not found. No POST requests have been logged yet.</div>';
}
echo '</div>';
// Display upload log
echo '<div class="log-section">';
echo '<h2>๐ Upload Log (upload_log.txt)</h2>';
if (file_exists('upload_log.txt')) {
$file_size = filesize('upload_log.txt');
$last_modified = date('Y-m-d H:i:s', filemtime('upload_log.txt'));
echo "<div class='stats'>";
echo "<strong>File Size:</strong> " . number_format($file_size) . " bytes<br>";
echo "<strong>Last Modified:</strong> $last_modified<br>";
echo "<strong>File Path:</strong> " . realpath('upload_log.txt');
echo "</div>";
if ($file_size > 0) {
$content = file_get_contents('upload_log.txt');
// Show last 3000 characters if file is too large
if (strlen($content) > 3000) {
$content = "...[File truncated - showing last 3000 characters]...\n\n" . substr($content, -3000);
}
echo '<div class="log-content">' . htmlspecialchars($content) . '</div>';
} else {
echo '<div class="info">๐ Log file is empty.</div>';
}
} else {
echo '<div class="error">โ upload_log.txt not found. No file uploads have been logged yet.</div>';
}
echo '</div>';
// PHP Configuration Info
echo '<div class="log-section">';
echo '<h2>โ๏ธ PHP Configuration (for debugging)</h2>';
echo '<div class="stats">';
echo "<strong>PHP Version:</strong> " . phpversion() . "<br>";
echo "<strong>Upload Max Filesize:</strong> " . ini_get('upload_max_filesize') . "<br>";
echo "<strong>Post Max Size:</strong> " . ini_get('post_max_size') . "<br>";
echo "<strong>Max Execution Time:</strong> " . ini_get('max_execution_time') . " seconds<br>";
echo "<strong>Memory Limit:</strong> " . ini_get('memory_limit') . "<br>";
echo "<strong>Current Directory:</strong> " . getcwd() . "<br>";
echo "<strong>Server Software:</strong> " . ($_SERVER['SERVER_SOFTWARE'] ?? 'Unknown') . "<br>";
echo "<strong>Document Root:</strong> " . ($_SERVER['DOCUMENT_ROOT'] ?? 'Unknown');
echo '</div>';
echo '</div>';
// Apache Log Files Info
echo '<div class="log-section">';
echo '<h2>๐ Apache Log Files</h2>';
echo '<div class="info">';
echo "Apache logs are typically located at:<br>";
echo "โข <strong>Access Log:</strong> C:\\xampp\\apache\\logs\\access.log<br>";
echo "โข <strong>Error Log:</strong> C:\\xampp\\apache\\logs\\error.log<br><br>";
echo "You can view these files using a text editor or the XAMPP Control Panel.";
echo '</div>';
echo '</div>';
?>
</div>
</body>
</html>
VISIT to http://localhost:8080/posttest/
And try to test every thing there;

After posting you are redirected toward
http://localhost:8080/posttest/process.php

For viewing The logs you can go through. detailed_post_log.txt
Test log entry - 06/16/2025 15:57:39
============================================================
POST Request Log - 2025-06-16 12:14:03
Client IP: ::1
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Request URI: /posttest/process.php
Server Name: localhost
Form - username: messi
Form - email: messi@gmail.com
Form - password: messiiiiii
Form - message: This is a test POST message
Header - Content-Type: application/x-www-form-urlencoded
Header - Content-Length: 94
Header - Referer: http://localhost:8080/posttest/
Header - Origin: http://localhost:8080
End Time: 2025-06-16 12:14:03
============================================================
============================================================
POST Request Log - 2025-06-16 12:14:27
Client IP: ::1
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Request URI: /posttest/process.php
Server Name: localhost
Form - username: thapa
Form - email: sarun@gmail.com
Form - password: secret123sas
Form - message: This is a test POST messagsse
Header - Content-Type: application/x-www-form-urlencoded
Header - Content-Length: 99
Header - Referer: http://localhost:8080/posttest/
Header - Origin: http://localhost:8080
End Time: 2025-06-16 12:14:27
============================================================
============================================================
POST Request Log - 2025-06-16 12:35:20
Client IP: ::1
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Request URI: /posttest/process.php
Server Name: localhost
Form - username: ronaldo
Form - email: ronaldo@gmail.com
Form - password: secret123
Form - message: This is a test POST ronaldo
Header - Content-Type: application/x-www-form-urlencoded
Header - Content-Length: 97
Header - Referer: http://localhost:8080/posttest/
Header - Origin: http://localhost:8080
End Time: 2025-06-16 12:35:20
============================================================
============================================================
POST Request Log - 2025-06-16 13:09:30
Client IP: ::1
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Request URI: /posttest/process.php
Server Name: localhost
Form - username: testuserdsdsada
Form - email: test@example.com
Form - password: secret123
Form - message: This is a tessaadsadsadast POST message
Header - Content-Type: application/x-www-form-urlencoded
Header - Content-Length: 116
Header - Referer: http://localhost:8080/posttest/
Header - Origin: http://localhost:8080
End Time: 2025-06-16 13:09:30
============================================================