Answer the question
In order to leave comments, you need to log in
How to organize a counter of calls to the script?
There is a script.
This script is called upon certain user actions.
It can be called both on the server side via CURL POST and on the user side via AJAX.
How can a counter be organized so that a user can call the script no more than 30 times during one visit to the site? Is there a solution so that the user cannot influence the counter - cookie substitution and all that?
Answer the question
In order to leave comments, you need to log in
Here is an example for you
<?php ## Пример работы с сессиями.
session_start();
// Если на сайт только-только зашли, обнуляем счетчик.
if (!isset($_SESSION['count'])) $_SESSION['count'] = 0;
// Увеличиваем счетчик в сессии.
$_SESSION['count'] = $_SESSION['count'] + 1;
?>
<h2>Счетчик</h2>
В текущей сессии работы с браузером Вы открыли эту страницу
<?= $_SESSION['count'] ?> раз(а).<br />
Закройте браузер, чтобы обнулить счетчик.<br />
<a href="<?= $_SERVER['SCRIPT_NAME'] ?>" target="_blank">Открыть дочернее окно браузера</a>.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question