473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

URGENT: Prevent default HTTP headers from being sent

Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>

When a webbrowser client requests data, it receives Apache server headers,
followed by my data:

HTTP/1.1 200 OK
Date: Tue, 28 Jun 2005 06:02:56 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b
DAV/1.0.2 PHP/4.1.2 mod_perl/1.26
X-Powered-By: PHP/4.1.2
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the data?
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.
I don't think this can be done with PHP, as it is probably handled by
apache.
If so, can I use Apache's RewriteEngine to accomplish this, in case
User-Agent is "^MyThinHardware.*" ?
How can I keep Apache from sending these headers?
=======================

I use the following php script to simulate a client requesting the php page,
and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "User-Agent: MyThinHardware/1.0\r\n";
$header .= "Content-Type: application/octet-stream\r\n";
$header .= "Content-Length: $size\r\n";
$header .= "Connection: close\r\n";
$header .= "\r\n";
/* post data */
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
die("$errstr ($errno)");
}
else {
fwrite($fp, $header);
fwrite($fp, $data, $size);
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
}
echo $response;
Jul 17 '05 #1
10 3018
Lisa Pearlson wrote:
Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>
<snip>
c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the
data? -
They shouldn't be there - most likely a charset issue - from the shell try
cat -v myscript.php
How do I prevent HTTP headers sent back to the client? I wish to
only send "Hello World!", without any headers.
Then you can't do it via HTTP / an apache module (actually, you probably
could, but it would ned a lot of hacking). Without HTTP though, there's no
defined way of getting parameters into your script.
The reason is that the
client will be a piece of hardware that expects binary data as response, <snip>
I use the following php script to simulate a client requesting the php
page, and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";

<snip>

There's something very broken here - the client wants to talk HTTP, but you
say that it won't listen to HTTP. R U sure?

C.
Jul 17 '05 #2
*** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.


Then, why use HTTP if the response must not follow the protocol rules? As
far as I know Apache will always send, at a minimum, the status line with
the numeric status code. Can't your write a simple daemon that listens in a
port? As you probably know you can write shell scripts in PHP.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3
Lisa Pearlson <no@spam.plz> wrote:
Transfer-Encoding: chunked

c
Hello World!
0

- Where do the 'c' and '0' come from? '0' just denoting the end of the data?
That is the chunked transfer encoding. See RFC 2616. Can be solved by
either supplying a content-length or by making http/1.0 requests instead
of http/1.1
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.
I don't think this can be done with PHP, as it is probably handled by
apache.


Then don't use a http daemon. You can run a serversocket with PHP and
have your system connect to that. OR you could simple evolve your
embedded system to understand HTTP. If the client makes a HTTP/1.0
request it can simply ignore output till after the first \r\n\r\n
sequence.

Jul 17 '05 #4
the client is dumb, it has no use for the http headers, it always expects a
fixed length binary data.
It can send headers just to please apache and make sure it gets to the right
script on the right domain.

I use http instead of writing my own daemon, so I can take advantage of
apache's features, such as handling a lot of simultaneous connections and
other tools meant for http, such as logging software etc. if I can use a
standard solution, it's always better than writing my own.. especially if it
suits all my needs except one minor one, useless headers.

Getting rid of these headers is only important because communication is very
expensive, per kilobyte of data.. so every byte I can save, leads to quite a
big saving.
"Colin McKinnon" <co**************@andthis.mms3.com> wrote in message
news:d9*******************@news.demon.co.uk...
Lisa Pearlson wrote:
Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>

<snip>

c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the
data? -


They shouldn't be there - most likely a charset issue - from the shell try
cat -v myscript.php
How do I prevent HTTP headers sent back to the client? I wish to
only send "Hello World!", without any headers.


Then you can't do it via HTTP / an apache module (actually, you probably
could, but it would ned a lot of hacking). Without HTTP though, there's no
defined way of getting parameters into your script.
The reason is that the
client will be a piece of hardware that expects binary data as response,

<snip>

I use the following php script to simulate a client requesting the php
page, and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";

<snip>

There's something very broken here - the client wants to talk HTTP, but
you
say that it won't listen to HTTP. R U sure?

C.

Jul 17 '05 #5
Writing my own server is risky.. both performance and stability with
concurrent connections is an issue. I prefer to use apache. Just need to
limit unused overhead as much as possible.

"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:1k*******************************@40tude.net. ..
*** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):
- How do I prevent HTTP headers sent back to the client? I wish to only
send
"Hello World!", without any headers. The reason is that the client will
be a
piece of hardware that expects binary data as response, not HTTP headers.


Then, why use HTTP if the response must not follow the protocol rules? As
far as I know Apache will always send, at a minimum, the status line with
the numeric status code. Can't your write a simple daemon that listens in
a
port? As you probably know you can write shell scripts in PHP.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--

Jul 17 '05 #6
> You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?

Lisa
Jul 17 '05 #7
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.

Jul 17 '05 #8
*** Lisa Pearlson wrote/escribió (Wed, 29 Jun 2005 02:36:09 +0200):
Writing my own server is risky.. both performance and stability with
concurrent connections is an issue. I prefer to use apache. Just need to
limit unused overhead as much as possible.


It seems unlikely to me that Apache+PHP offers better performance than only
PHP but of course's we'd need to benchmark the specific case. However, a
faster web server* may be a solution then (given that your embedded system
can finally understand HTTP).

(*) You have thttpd and some others

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #9
Interesting..
Hoever, like the article suggest, you need to take a lot of security
measures into account. I can't be messing with that.
Apache has evolved over many years..
I mean, it would take you only 2 days to write an HTTP web server in PHP,
but .. I wouldn't trust it, woud you?

Lisa

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.

Jul 17 '05 #10
Writing a HTTP server in PHP sounded so easy, I figured someone else already
thought of doing this:

http://nanoweb.si.kz/

"Lisa Pearlson" <no@spam.plz> wrote in message
news:42***********************@dreader24.news.xs4a ll.nl...
Interesting..
Hoever, like the article suggest, you need to take a lot of security
measures into account. I can't be messing with that.
Apache has evolved over many years..
I mean, it would take you only 2 days to write an HTTP web server in PHP,
but .. I wouldn't trust it, woud you?

Lisa

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.

Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.


Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Art | last post by:
Hello everyone, I am interested in starting an all volunteer website which will be directed at recovering missing children. I am aware that there are few other sites out there with the same...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
6
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
3
by: Ryu | last post by:
Hi, May I know how to prevent Javascript from being dlownloaded when the user saves at "View Source"? I have added "js" at IIS's application configuration's mapping and i have added the...
7
by: Gordon Smith | last post by:
I have four (4) ASP.NET Web applications/Web sites on a IIS/6 - Windows Server 2003 production server. 3 of them work fine. I just installed the 4th one and it's Application_Start event is not...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
10
by: dave Cheseldine | last post by:
Hi I want to stop a gd generated image from being cached. It is called into index.php file as follows: <image src = "http://www.daveches.co.uk/importimage/importimage.php?x=$randomNumber"...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
1
by: sohail28 | last post by:
Respected Sir /Madam, I create one web page which includes online reservation using phpscript. Now this page is working fine, but it executes on the same page. i want here, when i click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.