|
Posted by "Thomas Capote" on 10/20/86 11:24
Just to catch up:
I'm trying to respond to a HTTP POST request without sending any HTTP
headers with the response (that is, reply with *content only*).
1) The CGI SAPI will always send some basic headers with any script output;
these include the status line ('HTTP/1.1 200 OK'), 'Content-type:', 'Date:'
and 'Content-length:'.
2) While the 'q' switch ("php -q") is necessary and sufficient to suppress
HTTP header generation using the CLI ('command line interface'), it is not
clear to me how to apply this switch in a CGI configuration. Any ideas?
3) The header() command inserts or replaces headers to be sent by PHP.
However, header() (with no arguments) does not suppress header output, it
simply generates an error. Even if something like "header('Content-type:')"
suppressed the 'Content-type' header, how would we suppress all header
output including the status line ('HTTP/1.1 200 OK')?
4) Trying to use fsockopen() from the script receiving the POST request
fails because the client won't accept a redundant connection on the same
port/address it is currently using to issue the original POST request (it is
waiting for a response).
5) Mr. Lynch is right: this is NOT an HTTP compliant exchange. This is a bug
in the client machine that cannot be fixed (by me), but must be worked
around somehow.
6) All header information must be suppressed. That includes the status line,
too.
Tough little problem, eh guys?
I see three possible avenues to a solution.
1) Find some PHP command that will suppress header generation, or simply
circumvent it, if only as a side-effect.
2) Get Apache to not send headers for this page, maybe through SSI
directives, .htaccess file, or some other mechanism.
3) Write my own mini-server (to listen on port 6237 or something) to handle
these requests using socket calls in PERL, Java, or even the PHP CLI. I'm
not sure I could pull off programming something robust enough, frankly. I'd
rather hijack Apache to do the heavy lifting.
I'm not an expert in any of this, which is why I appreciate all the help I'm
getting. Thanks.
-----Original Message-----
From: Richard Lynch [mailto:ceo@l-i-e.com]
Sent: Thursday, August 18, 2005 3:48 AM
To: tg-php@gryffyndevelopment.com
Cc: php-general@lists.php.net; thomascapote@onlinenetworks.com
Subject: RE: [PHP] How to suppress HTTP headers?
On Tue, August 16, 2005 10:02 am, tg-php@gryffyndevelopment.com wrote:
> BTW: I made a mistake last time. Apparently with CLI there are
> headers. You can use "php -q" to suppress headers when using PHP via
CGI has always sent out at least one header.
Content-type: text/html
-q has always suppressed that.
CLI may or may not have sent headers...
> CLI. Odd. Not sure I had to do that when I wrote a few CLI scripts
> before. Oh well, something to play with another day (don't have time
> to check it right now).
>
> So another thing I may be wrong on.. but a thought.. If you use the
> header() command, does it prevent the web server from generating it's
> own headers?
I believe your header() commands only REPLACE any headers PHP would
have sent, but any other headers it's gonna send, it's still gonna
send them.
> That is, if you send out "<html><body>Something</body></html" does the
> web server automatically generate the headers but if you use header()
> it uses what PHP generates rather than it's own?
>
> If so.. can you just do:
> header();
>
> With nothing in it to suppress headers?
I think that will suppress headers... by issuing an ERROR that a
required argument is missing :-)
> Or can you do something like:
>
> header("<xml>stuff</xml>");
No.
That is not a valid header, for starters.
You MIGHT be able to "wipe out" the headers PHP sends by doing
something like:
header("Content-type:"); //Wipe out Content-type:
but I wouldn't cound on it.
Sounds to me like the remote server isn't actually using HTTP at all.
HTTP without headers is just not HTTP.
You may want to write your own "server" in PHP using sockets -- but
then you'll need to convince the remote server to connect/use that
different "server" you have written. Either connecting on a different
port, or to a different domain, or a different URL (maybe) so you can
configure your box to use your "server" for these weird requests.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|