Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:04:43+00:00 2026-06-01T20:04:43+00:00

I am working with a website where I will have several embedded YouTube videos.

  • 0

I am working with a website where I will have several embedded YouTube videos. I would like do two things.

  1. Attach a JavaScript listener to the videos to be able to tell if a video is played
  2. Send the corresponding data to a database using PHP

I understand that PHP will send the data server side, but I will already have the page loaded from JavaScript and the viewer may not resend a page to get that data into the database. My only other thought was AJAX, but I don’t have any experience with it.

I am thinking I should do something like this, but I am too new at JavaScript to know exactly how to implement this.

var video = document.getElementById('player1');

video.addEventListener("timeupdate", function() {
   if (this.currentTime >= 0) {
        //take in data from the video that it has been played
    }
}, false);

Then I am still left with sending the data to my database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:04:44+00:00Added an answer on June 1, 2026 at 8:04 pm

    I have not used the Youtube API before, but I believe the YouTube Javascript Player API is what you need.

    • player.getPlayerState() will tell you whether the player is playing, paused etc.

    • player.getCurrentTime() will tell you the number of seconds since the player started playing.

    Note: To use the JS api, you need to ensure it is enabled for the
    player in the player embed url:
    http://www.youtube.com/v/VIDEO_ID?version=3&enablejsapi=1

    Once you have collected the data you need, send it to your server using AJAX. This part will depend on the javascript library you are using or whether you are just writing the javascript yourself. I like to use YUI (which is made by Yahoo!). I would craft a request using IO and send the data as encoded JSON or POST.

    Then on the server side, the request would be received and then you can decode the JSON data into an array using json_decode() or just get the data out of your $_POST array, get the values you require and pop them in your database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a website that will have a high volume of
I am working on an website where users will have to pay a small
I am working on a online shopping website, it will have product images also.
I'm working on a website that will use features of social networking (like facebook
I am currently working on a social networking website, and I would like the
I'm writing multilingual website. I have several files on server like: /index.php /files.php /funny.php
I'm working on a website that will be using Facebook Connect to authenticate users.
I just started working on a website that will help people understand what rappers
A website I've been working on will not match data using a PHP (preg_match)
I'm working on an E-Book that will be published to my website. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.