0

I'm running into some small problems, I have this javascript, to update the VLC webplugin's stream, now I really want to insert some data into my database, to log how many are watching.

Here is my javascript code -

function changeVideo(filename) {
  var vlc = document.getElementById("tv");
  var options = [":http-user-agent=Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"];
  var URL = filename;
  var AddVid = vlc.playlist.add(URL, "", options);
  vlc.playlist.playItem(AddVid);
}

Here is my bottom link to activate the function

<a href="javascript:void();" onclick="javascript:changeVideo('<?=$row["link"] ?>');"><img src="./70x/<?=$row["image"] ?>" alt="<?=$row["name"] ?>" style="width:70px;height:auto;"></a></a>

How do I get the name and the timestamp into the database? :-/

6
  • Look at running AJAX. Commented Mar 6, 2015 at 23:43
  • i have no experience in AJAX at all, so i don't really know what to search for :-/ Commented Mar 6, 2015 at 23:44
  • I'd suggest jQuery and it's AJAX - api.jquery.com/jquery.ajax Commented Mar 6, 2015 at 23:48
  • Your questions seems incomplete. Where are you trying to insert values into the database? Commented Mar 6, 2015 at 23:52
  • when you click on the html link, it running the java function witch is updateing the stream VLC is playing. Here i want to insert the data of witch stream users have been played and when :) Commented Mar 6, 2015 at 23:57

2 Answers 2

1

First thanks to Maze Runner for the main code for the ajax handling. so here is what i did for get it to work, and secure.

Here is the code in the playerpage CREDIT TO Maze Runner

function changeVideo(filename,name) {
// here is the ajax call
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","infoSaver.php?name=" + name,true);
xmlhttp.send();

var vlc = document.getElementById("tv");
var options = [":http-user-agent=Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"]; 
var URL = filename;
var AddVid = vlc.playlist.add(URL, "", options);
vlc.playlist.playItem(AddVid);
}

Here is my code for the infoSaver.php

if (isset($_GET['id']) && is_numeric($_GET['id']))  {
$id = $_GET['id'];
  //check if id is vallid
$query1 = mysqli_query($db, "select * from channels WHERE active=1 AND `playid` = '$id' LIMIT 1");
while($row = mysqli_fetch_assoc($query1))   
{
$playid = $row["playid"];
}
if ($id == $playid) {
  // get the rest of the info
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
  // get name from DB
$query1 = mysqli_query($db, "select * from channels WHERE active=1 AND `playid` = '$id' LIMIT 1");
while($row = mysqli_fetch_assoc($query1))   
{
$name = $row["name"];
}
  // insert the entry
$query = mysqli_query($db, "INSERT INTO log (chname, chid, ip, time)
VALUES ('$name', '$id', '$ip', '$time')");
} else {
    echo '<p>The Id is not vallid</p>';
} 
} else {
    echo '<p>This page is protected</p>';
}

Thanks for all the help SO! your guys is the best! <3

Sign up to request clarification or add additional context in comments.

Comments

0

dont have your full code but based on what you have, here are my suggestions.

I would make $row["name"] a parameter to send to your function as well as link. so it becomes

changeVideo('<?=$row["link"] ?>','<?=$row["name"] ?>');

Create a seperate php file, say... infoSaver.php This file will have all the logic needed to save the name and time-stamp to db. You will get the name from the url string $_GET['name'] and the date is just time().

Put the ajax call inside your function

function changeVideo(filename,name) {
// here is the ajax call
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","infoSaver.php?name=" + name,true);
xmlhttp.send();

var vlc = document.getElementById("tv");
var options = [":http-user-agent=Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"]; 
var URL = filename;
var AddVid = vlc.playlist.add(URL, "", options);
vlc.playlist.playItem(AddVid);
}

Its a simple solution thats most apps will need to implement

3 Comments

Will this not add an huge security risk? people kan manually edit the live html data, and insert wrong infomations into the database? and thanks for your time, i will test it in just an moment :)
The info will be sent when they click the button. They would have to inspect element change the name value and then click. Thats alot for someone who wants to hide what films they are watching. Only other thing I can think of is to put the ajax request in an external .js file then it wont be so easy to figure out how your app works but if they really want to hide what they are watching they will go the extra mile to do that. I will think on it for a better solution. If you find a better or more secure way please post your answer here to answer your own question.
Thanks :), i think i have an idea, i can make a check in the database, if the example the movie title is in the database, if the movie name = movie name {} else {}?? then there is no way to put false infomation onto the DB :)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.