get recently played

This gets the recently played tracked by the user.

$key='key';
$secret='secret';
$music_token='token';
	
$url='http:ws.audioscrobbler.com2.0?method=user.getrecenttracks&user={username}&limit=12&api_key=' . $key;
	
$music = simplexml_load_file($url);
	
foreach ($music->recenttracks->track as $track) {
	$nowplaying = $track->attributes()->nowplaying;
	$artist=$track->artist;
	$name=$track->name;
	$album=$track->album;
	$url=$track->url;
	$image=$track->image[3];
	$date=$track->date;
	$date=strtotime($date);
	$ago=time_elapsed_B($nowtime-$date);
	if($nowplaying=='true'){
		$ago='now playing'; 
	}
}