Не уверен, имеет ли это какое-либо отношение к этому, но мой компьютер находится в UTC-3:30 Ньюфаундленда, но когда я поднимаю список, он запускает обратный отсчет: 3 часа 29 минут 59 секунд, пока я не смогу ударить снова, что должно быть всего +2 часа с момента последнего_bump.
Вот мой код:
my- server.php (PHP)
Код: Выделить всё
$lastbump = new DateTime($row['last_bump']);
$nextbump = new DateTime($row['last_bump']);
$nextbump->add(new DateInterval('PT2H'));
$currenttime = new DateTime();
if ($currenttime >= $nextbump) {
echo '[url=#]Bump Server[/url]';
} else {
// Calculate time difference in seconds
$timeDiff = $nextbump->getTimestamp() - $currenttime->getTimestamp();
echo '';
}
Код: Выделить всё
function startCountdown(element, time) {
let countdownTime = time;
const updateCountdown = () => {
if (countdownTime > 0) {
countdownTime--;
const hours = Math.floor(countdownTime / 3600);
const minutes = Math.floor((countdownTime % 3600) / 60);
const seconds = countdownTime % 60;
// Create a readable countdown string
let countdownText = 'Next Bump: ';
if (hours > 0) {
countdownText += `${hours}h `;
}
if (minutes > 0 || hours > 0) {
countdownText += `${minutes}m `;
}
countdownText += `${seconds}s`;
element.innerText = countdownText;
} else {
element.innerText = 'You can bump now!';
clearInterval(countdownInterval);
location.reload(); // Refresh the page to show the bump button
}
};
updateCountdown(); // Initial call to display the timer
const countdownInterval = setInterval(updateCountdown, 1000);
}
// Initialize countdown for each countdown element
document.querySelectorAll('.countdown').forEach(element => {
const time = parseInt(element.getAttribute('data-time'), 10);
startCountdown(element, time);
});
Код: Выделить всё
include '../functions.php'; // Adjust path as per your file structure
// Ensure POST data exists and is JSON
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, true);
// Ensure JSON data was successfully decoded
if ($input === null) {
http_response_code(400); // Bad request
echo json_encode(array('error' => 'Invalid JSON data'));
exit;
}
// Retrieve and sanitize server_id from JSON data
$server_id = isset($input['server_id']) ? intval($input['server_id']) : null;
if (!$server_id) {
http_response_code(400); // Bad request
echo json_encode(array('error' => 'Invalid server ID'));
exit;
}
// Perform database update to set last_bump timestamp
$stmt = $conn->prepare("UPDATE servers SET last_bump = NOW() WHERE id = ?");
$stmt->bind_param('i', $server_id);
if ($stmt->execute()) {
// Success response
http_response_code(200); // OK
echo json_encode(array('success' => true));
} else {
// Error response
http_response_code(500); // Internal server error
echo json_encode(array('error' => 'Failed to update server bump'));
}
$stmt->close();
Изменить:
При удалении «date_default_timezone_set('Америка/Торонто');» - Я могу постоянно качать серверы, не дожидаясь ни минуты...
Подробнее здесь: https://stackoverflow.com/questions/787 ... -php-mysql