eMusic Forums

Showcase

RSS Feed

Sample PHP artist page redirect

  1. I needed something to take an artist name and redirect to their emusic page. Here's what I came up with. Any feedback would be appreciated:

    <?php

    // This page expects Artist Name to be included in the querystring: ?a=Wilco
    parse_str(($_SERVER['QUERY_STRING']));

    if ( $a )
    {

    if ( $xml = simplexml_load_file('http://api.emusic.com/artist/search?apiKey=myKey&term=' . $a .'&fref=400072', 'SimpleXMLElement', LIBXML_NOCDATA) )
    {

    $url = $xml->artists->artist[0]['url'];

    if ($url)
    {
    header ("Location: $url");
    } else {
    // no artist found -- send them to Taro Sound!
    header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
    }
    } else {
    exit('Failed to open.');
    }

    } else {
    // no artist passed -- send them to Taro Sound!
    header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
    }

    ?>

    Message edited by gloriousnoise 8 months ago

  2. Nicolas Chevallier1 year ago

    Thanks for sharing, I use some code to developp a future webservice based on emusic.

  3. juliston8 months ago

    Thanks for your code

[ Page 1 of 1 ]