last fm recent tracks


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $cache_file = "/path/to/cache_file.htm";
  2. $force_update = false;
  3.  
  4. if (filemtime($cache_file)+600 < time() || $force_update) {
  5.  
  6.  
  7. $username = "YOUR_USER_NAME";
  8. $api_key = "YOUR_API_KEY";
  9.  
  10. $url = "http://ws.audioscrobbler.com/2.0/?format=json&method=user.getrecenttracks&";
  11. $url .= "user=" . $username . "&api_key=" . $api_key;
  12.  
  13. $data = @curlContents($url);
  14. $data = @json_decode($data, true);
  15.  
  16. if (isset($data['recenttracks']['track'])) {
  17. echo '<ul>' . "\n";
  18. foreach ($data['recenttracks']['track'] as $track) {
  19. echo '<li>' . $track['artist']['#text'] . ' - ' . $track['name'] . '</li>' . "\n";
  20. }
  21. echo '</ul>' . "\n";
  22. }
  23.  
  24. $contents = ob_get_contents();
  25.  
  26. file_put_contents($cache_file, $contents);
  27.  
  28. }
  29.  
  30. else {
  31. $contents = file_get_contents($cache_file);
  32. }
  33.  
  34. echo $contents;

URL: http://bettesmidler.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.