website/static/php/log.php
Andreas Hnida 67a64b1bf8
All checks were successful
Build and Deploy Hugo Site / buildAndDeploy (push) Successful in 54s
fixed Typos from plan.io ticket
2024-05-13 13:21:01 +02:00

20 lines
672 B
PHP

<?php
// Check if the request is a POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Assuming data is sent via a POST field named 'logData'
$logData = $_POST['logData'] ?? 'Default log entry.';
// Specify the log file
$logfile = '../log.txt';
// Write or append the data to the file
file_put_contents($logfile, $logData . "\n", FILE_APPEND);
// Send a response back to JavaScript
echo json_encode(["status" => "success", "message" => "Data logged successfully"]);
} else {
// Handle incorrect request method
http_response_code(405);
echo json_encode(["status" => "error", "message" => "Method not allowed"]);
}
?>