This is what I have so far
<?php
//max recent tracks to keep in the recently played tracks history
$max_recent = 100;
//secret key to access the script
$key = '';
//check access
if ($_REQUEST['key'] !== $key) {
ReturnError(400, 'Invalid key');
}
//artist/title info
$artist = $_REQUEST['artist'];
$title = $_REQUEST['title'];
$album = $_REQUEST['album'];
$bpm =$_REQUEST['bpm'];
$comment = $_REQUEST['comment'];
//title to display
$t = htmlspecialchars($artist . ' - ' . $title);
$file = 'nowplaying_title.txt';
//recent tracks history
$recent = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$recent = array_slice($recent, 0, $max_recent);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Now playing</title>
</head>
<body>
<!-- current track title (begin) -->
<b>Now Playing: <span id="np_current_track"></span></b>
<br><br>
<!-- playing track artwork (begin) -->
<b>Playing track artwork:</b>
<br>
<img id="np_track_artwork" src="nowplaying_artwork.png" alt="Playing track artwork" width="200" height="200">
<script>
function updateArtworkDisplay() {
document.querySelector('#np_track_artwork').src = 'nowplaying_artwork.png?' + new Date().getTime();
}
//update every 10 seconds
document.addEventListener('DOMContentLoaded', function () {
setInterval(updateArtworkDisplay, 10000);
});
</script>
<br>
<br>
<!-- playing track artwork (end) -->
<b>Recently played tracks: </b>
<div id="np_recent_tracks"></div>
<script>
//update every 5 seconds
document.addEventListener('DOMContentLoaded', function () {
setInterval(updateTitleDisplay, 5000);
updateTitleDisplay();
});
</script>
<!-- current track title (end) -->
<br>
<!-- send track name to SQL-->
$myUser = "";
$myPass = "";
$myDB = "";
$conn = mssql_connect($myServer,$myUser,$myPass);
if (!$conn)
{
die('Not connected : ' . mssql_get_last_message());
}
$sql = "select * from played_songs";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["datetime"]. " - Name: " . $row["artist"]. " " . $row["song"]. "<br>";
}
} else {
echo "0 results";
}
$db_selected = mssql_select_db($myDB, $conn);
if (!$db_selected)
{
die ('Can\'t use db : ' . mssql_get_last_message());
} else {
$sql = "SELECT * FROM played_songs";
$result = $conn->query($sql);
if ($result->num_rows > 100) {
$sql = "DELETE FROM played_songs WHERE num_rows='100' ";
}
<!-- No need to insert at top as we are date &time encoded -->
$sql = "INSERT INTO played_songs VALUES (date('l jS \of F Y h:i:s A'),$song, $artist , $album,$bpm,$comment); "
}
$mysqli_close(conn);
</body>
</html>
//album cover
$artwork = isset($_REQUEST['artwork']) && ($_REQUEST['artwork'] !== '') ? $_REQUEST['artwork'] : false;
if ($artwork !== false) {
$artwork = base64_decode($artwork);
$r = fopen('nowplaying_artwork.png', 'wb');
if ($r !== false) {
fwrite($r, $artwork);
fclose($r);
} else {
ReturnError(500, 'Failed to write artwork to a file');
}
}
function ReturnError($code, $text) {
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
header($protocol . ' ' . $code . ' ' . $text);
exit();
}
?>