Find spotify information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Find spotify information

Post by JKM »

I want to find spotify information from a Spotify link, and I found a site where I can find it.

Code: Select all

<?php
    if(strlen($_GET['uri']) == 22) {
        $url = file_get_contents("http://spotify.url.fi/track/".$_GET['uri']);
        preg_match('/<title>(.*)<\/title>/i',$url,$output);
        $explode = explode("&mdash;", $output[1]);
        print_r($explode);
?>
    [Spotify Info:] <?php echo $artist; ?> - <?php echo $song; ?> [<?php echo $album; ?>]
<?  
    } else {
        echo 'Error - wrong link format.';
    }
?>
Warning: file_get_contents(http://spotify.url.fi/track/4OSRg1faLprPCt86C80zWt) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /public_html/spotInfo.php on line 3
How do I solve this, and if it's not possible, does anyone know a way to find spotify information?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Find spotify information

Post by cpetercarter »

My guess is that allow_url_fopen is set to 'off' in your php.ini file. This is a security measure intended to prevent remote file execution hacks, so even if you can change this setting it would probably be better not to.

The alternative is to use cURL to access the remote URL. Google 'cURL' - you'll find lots of examples.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Find spotify information

Post by JKM »

Nevermind, I found a way. Thanks for your help!
Post Reply