Tekforums

Chat => Entertainment & Technology => Topic started by: M3ta7h3ad on April 08, 2007, 06:41:36 AM

Title: Little less lame question involving PHP :)
Post by: M3ta7h3ad on April 08, 2007, 06:41:36 AM
I have a problem.

I can access the usual HTTP headers of a page using the usual PHP methods of $_SERVER[HTTP_Referrer] or whatever... I can also list all the headers using:

$headers = headers_list();
foreach($headers as $header){
echo $header. "
"
}

But... I have a plug-in that "pings" a page from winamp (doesnt display the page, just tells a script to run with the information it sends in a seperate file sent over SFTP), that will send a custom header called "X-NowPlaying" containing a unique code/hash that can identify the person pinging the script.

which would be quite useful for what I am trying to do.

Question is... $_server[X-NowPlaying]; results in an error of:

QuoteUndefined index: X-NowPlaying in /nfs/mntI4/projectsite/R.I.L.Hicks/test_head.php on line 6

So clearly that doesnt work, any ideas on how to access a specific HTTP header?
Title: Little less lame question involving PHP :)
Post by: Sweenster on April 08, 2007, 11:25:09 AM
You need to put each of the headers into a list

$headers = headers_list() ;
while (list($key, $val) = each($headers)) {

if($key == X-NowPlaying ) ...

}

Not sure that will work but it seems to be the best way

Or possibly using getallheaders()
Title: Little less lame question involving PHP :)
Post by: M3ta7h3ad on April 08, 2007, 12:26:32 PM
Right... sorted it.

My Solution :)

[code]
$headers = headers_list() ;
foreach($headers as $header){
$test = explode(":", $header);
if ($test[0] == "X-NowPlaying"){
   $uid = $test[1];
}
}

Edit: Dammit... it doesnt work.
Title: Little less lame question involving PHP :)
Post by: Sam on April 09, 2007, 08:06:54 AM
Why dont you write out the headers to a file so you can see if its coming across exactly as you expect. It might be X-Now-Playing or X-NowPlaying[space] or something.
Title: Little less lame question involving PHP :)
Post by: Sweenster on April 09, 2007, 13:36:25 PM
thought i would update this as he hasnt

he has fixed it with a $_Server[http_X-NowPlaying]

tis either that or something very close

he will post it in here at some point
Title: Little less lame question involving PHP :)
Post by: M3ta7h3ad on April 09, 2007, 15:51:12 PM
thats what I ended up doing Sam. But it ended up being something like sweenster said, I tried it I was sure... but must have been the one combination I didnt try.

$_SERVER[HTTP_X_NowPlaying] was the variable name. :)