News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

Little less lame question involving PHP :)

Started by M3ta7h3ad, April 08, 2007, 06:41:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

M3ta7h3ad

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?

Sweenster

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()

M3ta7h3ad

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.

Sam

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.

Sweenster

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

M3ta7h3ad

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. :)