20 lines
672 B
PHP
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"]);
|
||
|
|
}
|
||
|
|
?>
|