Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you really need to make sure that a link only creates an event once, then you need to implement a token system, where when a hyperlink (or a form post target) is generated, a use once token is generated and stored (in the session or wherever), and then is checked in the calling script.</p> <p>So your hyperlink may look like this:</p> <pre><code>&lt;a href='download.php?token={some-token}&amp;f={$item['name']}&amp;t={$type}' target='_blank'&gt;{$item['name']}&lt;/a&gt; </code></pre> <p>On the php side this is a really simplified idea of what you might do:</p> <pre><code>&lt;?php session_start(); if (!isset($_REQUEST['token']) die(); // or fail better if (!isset($_SESSION['oneTimeTokens'][$_REQUEST['token']) die(); // or fail better if ($_SESSION['oneTimeTokens'][$_REQUEST['token']=='used') die(); // or fail better $_SESSION['oneTimeTokens'][$_REQUEST['token']='used'; // we're good from this point </code></pre> <p>This would solve the effects of your problem, though not the double running itself. However since you want to make sure a link is firing an event only once NO MATTER WHAT, you probably implement this in some form or another as it's the only way to guarantee that any link generated has a one real use life that I can think of.</p> <p>When generating the link you would do something like this in your code:</p> <pre><code>&lt;?php $tokenID = {random id generation here}; $_SESSION['oneTimeTokens'][$tokenID] = 'not used'; </code></pre> <p>I'd also somewhere put a cleanup routine to remove all used tokens. Also, it's not a bad idea to expire tokens beyond a certain age, but I think this explains it.</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.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COIf I am understanding you correctly, you are stating to create an individual token on the 'view.php' page that is inserted into the listing of the download links? Then in the PHP script check that token and continue/fail as necessary. That would prevent a link from being valid at another session, but I do not see how it would prevent a double execution of the script by itself. (The question posed is based on the user clicking the download link only once). It is the script that is being executed twice or more.
      singulars
    2. COI'm guessing something is firing the same request multiple times. If you added a token to the request link, then even if the link were called multiple times, each time the link was called the same token would be passed. However, proper use of tokens, especially when paired with a database transaction, can prevent the script from completing multiple times. You aren't preventing multiple executions of the script. You're just preventing it from running to completion other than the first call.
      singulars
    3. COThanks for the reply clarifying your answer. I too have thought of a way to prevent multiple database entries, but not yet the multiple executions. I wrapped the insert/update statement in an if statement that checks for the existence of the referrer, and if present it'll execute the SQL. If not and the last request was within 1 second, it'll skip over the insert/update. Temporary fix until properly fixed. I'm going to accept your answer as I'll look to implement the token and DB method for checks versus what I have currently. Thanks.
      singulars
 

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