Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading and Writing Headers

Google Mike
Guest
 
Posts: n/a
#1: Jul 17 '05
Gosh. I posted this earlier on Google Groups, but it didn't appear.
Perhaps there was a problem at Google. Forgive me for posting it
again. This time, I'll be more brief.

Instead of using cookies, I want to play with HTTP headers in general
because I heard you can use these to circumvent cookie
security/cleaner type apps (which I consider silly, btw). I want to
write custom headers like:

TRACK_fullname: Google Mike

I want to load a PHP page, write a custom header like that, then write
a Location header to redirect to another page, as in:

header('TRACK_fullname: Google Mike');
header('Location: test2.php');
exit;

On test2.php, I want to read this back. I cycle through the array
returned by getallheaders(), but I don't see "TRACK_fullname" in
there.

What's the catch?

Alan Little
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Reading and Writing Headers


Carved in mystic runes upon the very living rock, the last words of
Google Mike of comp.lang.php make plain:
[color=blue]
> I want to load a PHP page, write a custom header like that, then write
> a Location header to redirect to another page, as in:
>
> header('TRACK_fullname: Google Mike');
> header('Location: test2.php');
> exit;
>
> On test2.php, I want to read this back. I cycle through the array
> returned by getallheaders(), but I don't see "TRACK_fullname" in
> there.[/color]

The header() function sends response headers to the browser. The browser
sees the Location: header and generates a new request for that resource.
It has no idea what your custom header means, and has no reason to pass
it on in the request.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
BKDotCom
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Reading and Writing Headers


googlemike@hotpop.com (Google Mike) wrote in message news:<25d8d6a8.0310091748.22572f71@posting.google. com>...
[color=blue]
> I want to load a PHP page, write a custom header like that, then write
> a Location header to redirect to another page, as in:
>
> header('TRACK_fullname: Google Mike');
> header('Location: test2.php');
> exit;
>
> On test2.php, I want to read this back. I cycle through the array
> returned by getallheaders(), but I don't see "TRACK_fullname" in
> there.
>
> What's the catch?[/color]

Unless your user has some special browser that recognises
'TRACK_fullname', it's just going to be ignored. The browser isn't
a header messenger.
sk
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Reading and Writing Headers


The only headers of this kind that you can send out like this and pick
up in the browser are, yes, cookies.

Of course, if what you want to do is pass something along to track in
your redirect and not worry about cookies, you can either use sessions
(for a redirect within the same site) or just set your own GET parameter
in the redirect URL, as in:

header('Location: test2.php?TRACK_fullname=Google%20Mike');

Google Mike wrote:[color=blue]
> Gosh. I posted this earlier on Google Groups, but it didn't appear.
> Perhaps there was a problem at Google. Forgive me for posting it
> again. This time, I'll be more brief.
>
> Instead of using cookies, I want to play with HTTP headers in general
> because I heard you can use these to circumvent cookie
> security/cleaner type apps (which I consider silly, btw). I want to
> write custom headers like:
>
> TRACK_fullname: Google Mike
>
> I want to load a PHP page, write a custom header like that, then write
> a Location header to redirect to another page, as in:
>
> header('TRACK_fullname: Google Mike');
> header('Location: test2.php');
> exit;
>
> On test2.php, I want to read this back. I cycle through the array
> returned by getallheaders(), but I don't see "TRACK_fullname" in
> there.
>
> What's the catch?[/color]

Closed Thread