Page 1 of 1

Trouble with getenv('QUERY_STRING')

Posted: Thu Nov 26, 2009 5:06 pm
by Paranoid
Hi, I wasn't sure if I should post this in the PHP forum or the JS forum but I'm pretty sure the problem is PHP related.
I have been using YUI 2.7.0 (http://developer.yahoo.com/yui/), and I have been trying to make something similar to this:

http://developer.yahoo.com/yui/examples ... ather.html

The code as it is, WORKS fine.
It's a pretty simple example, and I tried working my way implement something similar but I kept having getenv('QUERY_STRING') being nothing (i.e. empty). I went to the extend of just using the exact same code as given there with just one change in the php file.
This line of code:

Code: Select all

$url = 'http://xml.weather.yahoo.com/forecastrss?'.getenv('QUERY_STRING');
was changed with this:

Code: Select all

$url = 'http://developer.echonest.com/artist/'.getenv('QUERY_STRING').'/audio.rss';
With just changing 1 line in the PHP file, the getenv('QUERY_STRING') becomes nothing and the XML returned gives me an error because of this. It just stops working just by changing a single line, which is a valid url. How is that possible? I can't understand this.

Re: Trouble with getenv('QUERY_STRING')

Posted: Thu Nov 26, 2009 6:11 pm
by requinix
You should be using $_SERVER instead of getenv.

Code: Select all

$url = 'http://developer.echonest.com/artist/' . $_SERVER["QUERY_STRING"] . '/audio.rss';
You sure that's the right URL to be using? Shouldn't the thing between /artist/ and /audio.rss be an artist's name? Because QUERY_STRING is not that.

Re: Trouble with getenv('QUERY_STRING')

Posted: Thu Nov 26, 2009 6:24 pm
by Paranoid
I tried using $_SERVER, but that didn't work either.

Yeah, QUERY_STRING is an artist name that I pass via a form that the user is prompted to enter. Using Firebug I even see that the artist name is passed as it should:

Code: Select all

GET http://.../Artist.php?p=Muse
(I just put the dots to avoid writing the whole thing, pretty long)

Looking at the output from Firebug, it says the parameter I used is correct (p as muse), but the response is just an XML file with an error response since the call was http://developer.echonest.com/artist//audio.rss instead of http://developer.echonest.com/artist/Muse/audio.rss (for example) as it should be...

Re: Trouble with getenv('QUERY_STRING')

Posted: Thu Nov 26, 2009 7:32 pm
by requinix
The URL used would have been

Code: Select all

http://developer.echonest.com/artist/p=Muse/audio.rss
which is why I questioned your use of QUERY_STRING.

Are you absolutely sure that the artist is blank? What's telling you that?

Re: Trouble with getenv('QUERY_STRING')

Posted: Thu Nov 26, 2009 7:59 pm
by Paranoid
I knew it was blank because I tried another API call from another service that has very specific error messages and it returned that no value was passed, i.e. blank.

Thankfully, I have figured this out; the problem was not my php code, which remains as is, but my JS and more specifically a YAHOO specific part of the code. It seems that the code example on their website might not be updated as I looked at the API documentation and some calls did not agree with the example provided.

Thanks for your help tasairs.