Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you have some cookie set on the user, when the AJAX request arrives it will also contain the cookie. Write a function to validate the cookie (eg: <code>isUserLoggedIn()</code>) and monitor how often the user requests a page:</p> <pre><code>$minLoggedOutRequestDelay = 3; // Set up the variable for the first time if (! isset($_SESSION["lastAjaxRequest"])) { $_SESSION["lastAjaxRequest"] = 0; } if ($_SESSION["lastAjaxRequest"] - microtime() &gt; $minLoggedOutRequestDelay AND (! isUserLoggedIn())) { // Do something to stop the request from going through // or maybe just log it } $_SESSION["lastAjaxRequest"] = microtime(); // Continue as normal </code></pre> <p>This will cause only one tab to work at once. If they have multiple open, the 'active' tab may switch between tabs due to network latency. To check based on how many tabs are open and make one work perfectly and the others not at all, you'll need a random number generated on page load. Include it as part of the AJAX request to tell the different pages apart (eg: <code>...&amp;pageRandomNumber=828918&amp;...</code>:</p> <pre><code>$minLoggedOutRequestDelay = 3; $maxLoggedOutPages = 1; // Set up the array in case its the first time if (! isset($_SESSION["lastAjaxRequest"])) { $_SESSION["lastAjaxRequest"] = array(); } // Trim inactive pages from the array foreach ($_SESSION["lastAjaxRequest"] as $pageRandomNumber =&gt; $lastTime) { if ($lastTime - microtime() &gt; $minLoggedOutRequestDelay * 2) { unset($_SESSION["lastAjaxRequest"][$pageRandomNumber]); } } // Make sure the current page is initialised if (! isset($_SESSION["lastAjaxRequest"][$_REQUEST["pageRandomNumber"]])) { $_SESSION["lastAjaxRequest"][$_REQUEST["pageRandomNumber"]] = 0; } if ((! isUserLoggedIn()) AND count($_SESSION["lastAjaxRequest"]) &gt; $maxLoggedOutPages) { // Do something to stop the request from going through // or maybe just log it } $_SESSION["lastAjaxRequest"][$_REQUEST["pageRandomNumber"]] = microtime(); // Continue as normal </code></pre> <p>Its possible for pageRandomNumber to be the same on multiple tabs, but highly unlikely given sufficient digits.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload