I have a blog/vlog where I also share my listening habits from Spotify live. I use a little snippet called Snip (available on Github) that fetches my Spotify stream, creates text files for my data (like track, artist, album and trackID)
Now I wanted to add a link on my webpage to the actual track I am playing using the variable $i for trackID
I've come up with this code thanks to some googling and tips/trix pages:
<?php
$myfile = fopen("Snip_TrackId.txt", "r") or die("Die!");
echo "<a href='https://open.spotify.com/track/";
echo fread($myfile,filesize("Snip_TrackId.txt"));
echo "'target='_blank'><img width='18px' height='18px' title='Open with Spotify' src='np_spotify.png'><a/> <- Listen";
fclose($myfile);
?>
This works just fine, but when I close down Spotify or pause, the text files empty themselves and my info box turns blank AND THAT'S THE WAY IT SHOULD BE :). B ut...... With my code above, the link, image and text "<- Listen" is still visible and I've been trying to figure out how I can fix this but I'm stuck. (The link is also not really working as it only points to the part without the trackID)
So now I turn to you. Can you help me with a working solution for this? If not, I will probably just keep things as they are.