title: secure way to count video plays
body: <p>I've been trying to think of ways to check the validity of plays on any given video that has been served to a user. I don't want to be updating the counter every time a user hits the play button as this could be easily abused. Not only that, the user could always visit the <strong>Ajax</strong> request page which updates the plays directly and then just click refresh until their hearts content. </p>
  
  <p>For an issue I'd assume to be fairly popular, I can't seem to find anything based on the security of it. </p>
  
  <p>One idea I thought might be good would be to check would be to see how much of the content has been streamed when serving the file via <strong>PHP</strong> - but according to <a href="https://stackoverflow.com/a/30152758/5859909"><strong>this</strong></a> answer, that is impossible.</p>
  
  <p>So, how should I approach this problem? Do I bite the bullet and just <em>hope</em> that users don't abuse the system (which they definitely will) or is there any solution to this problem?</p>
  
  <p>Cheers.</p>
  
  <p><strong>EDIT:</strong> Here's an example of something I'd be looking for...</p>
  
  <pre class="lang-php prettyprint-override"><code>$file = new File($path);
  $read = $file-&gt;read();
  while($read-&gt;reading()){
      // if 30 seconds has elapsed
      if($read-&gt;elapsed() &gt; 30000){
          // query database
      }
  }
  </code></pre>