Save time user watched video and continue watching

Asked

Viewed 146 times

0

Well, I finished a course in PHP, I’m not an expert and I’m creating a course system. I need that when the user starts attending the class, the system saves the running time of the video every 3 seconds. And save it so that the next time he enters the site, he can pick up where he left off! I thought I’d do it with localStorage, cookies and others. But I need that from where the user access, he can continue watching. I thought about sending the time to the Database. I just don’t know what structure and function to do it. Could you help me?

1 answer

1

I recommend you use Ajax

Here’s a feature to send data to the server without updating the page.

function SendDataToServer(_data)
{
  var xmlhttp = new XMLHttpRequest();
  //
  xmlhttp.onreadystatechange = function() {
      //
      if (this.readyState == 4 && this.status == 200) {
          // Aqui podes ignorar se nao quiseres receber nada do servidor
          console.log("Texto recebido do servidor -> " + this.responseText);
      }
  };
  // Aqui envia os dados 
  xmlhttp.open("GET", "php/TeuFicheiro.php?data="+_data, true);
  xmlhttp.send();
}

You can call it

setInterval(function(){ 
    SendDataToServer("Utilizador X assistiu X segundos");
}, 3000);

setInterval(function, time) calls the function every 3 seconds

Browser other questions tagged

You are not signed in. Login or sign up in order to post.