Are there any existing PHP scripts or libraries that can assist in marking visited links for audio files on a website?

When a user visits a webpage with audio files, it can be useful to mark the links to those files as visited to provide a better user experience. One way to achieve this is by using PHP to set a cookie when a link is clicked, and then checking for that cookie to style the link as visited when the page reloads.

<?php
// Check if the audio file link has been visited
if(isset($_COOKIE['visited_audio_files']) && in_array('audio_file1.mp3', $_COOKIE['visited_audio_files'])){
    echo '<a href="audio_file1.mp3" style="color: gray; text-decoration: line-through;">Audio File 1</a>';
} else {
    echo '<a href="audio_file1.mp3">Audio File 1</a>';
}

// Set the cookie when the audio file link is clicked
if(isset($_GET['audio_file']) && $_GET['audio_file'] == 'audio_file1.mp3'){
    $visited_files = isset($_COOKIE['visited_audio_files']) ? $_COOKIE['visited_audio_files'] : [];
    $visited_files[] = 'audio_file1.mp3';
    setcookie('visited_audio_files', json_encode($visited_files), time() + (86400 * 30), '/');
}
?>