Initial commit: существующий сайт + конфигурация разработки
Some checks failed
Deploy to Production / deploy (push) Failing after 4s
Some checks failed
Deploy to Production / deploy (push) Failing after 4s
This commit is contained in:
30
html/api/counter.php
Normal file
30
html/api/counter.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// Простой обработчик счетчика
|
||||
header('Content-Type: application/json');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: POST, GET');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
$counterFile = __DIR__ . '/counter.txt';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Получаем данные от JavaScript
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$count = isset($data['count']) ? intval($data['count']) : 1;
|
||||
|
||||
// Записываем в файл
|
||||
file_put_contents($counterFile, $count);
|
||||
|
||||
echo json_encode(['status' => 'success', 'count' => $count]);
|
||||
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
// Возвращаем текущее значение
|
||||
if (file_exists($counterFile)) {
|
||||
$count = file_get_contents($counterFile);
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
echo json_encode(['count' => intval($count)]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user