website/static/php/log.php

20 lines
672 B
PHP
Raw Permalink Normal View History

2024-05-13 13:21:01 +02:00
<?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"]);
}
?>