0

Having recently had some problems with my code which calls for artist data fed from Last.FM API, I'm looking for a different solution but am struggling to find a nice easy way to handle the problem. Currently I have:

    <?php $feed = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=01234567890");
$xml = simplexml_load_file($feed);
$info = $xml->artist->bio->summary; ?>

<?php echo $info; ?> 

Obviously, this is a problem for security as I don't want to enable fopen. Can anyone point me in the direction of a solution? Most people suggest cURL but I have no clue about using it so would be grateful for some help there.

N.N.
  • 8,336
  • 12
  • 54
  • 94

2 Answers2

0

cURL is a PHP library. Here are some links that explain it well:

http://themekraft.com/getting-json-data-with-php-curl/ http://www.jonasjohn.de/snippets/php/curl-example.htm

For others who may read this: If your hosting company doesn't have fopen enabled, you may be able to create a "local" php.ini file in your web root directory with this line:

allow_url_fopen = ON
0

You called simplexml_load_file twice. Try:

<?php

$feed = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=YOUR_KEY';
$xml = simplexml_load_file($feed);
$info = $xml->artist->bio->summary;

echo $info;

cURL version:

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=YOUR_KEY');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$xml = curl_exec($ch);
curl_close($ch);

$xml = simplexml_load_string($xml);
michalzuber
  • 5,079
  • 2
  • 28
  • 29