473,586 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passthru + auto generated headers

Hello,

I'm slightly confused with the passthru() command. The program I call writes
html headers itself. However, passthru() makes apache sending some generated
headers first. There's no fault with spaches in the code etc, I think.
Here's an simplified example:
$ cat /www/example.php
<?
passthru("cat /tmp/output");
?>
$ cat /tmp/output
Content-Type: text/html

<HTML><HEAD></HEAD>Message</BODY></HTML>
$ curl -i "http://localhost/example.php"
HTTP/1.1 200 OK
Date: Sat, 16 Jul 2005 14:47:29 GMT
Server: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7d DAV/2 PHP/5.1.0b3
X-Powered-By: PHP/5.1.0b3
Content-Length: 66
Content-Type: text/html

Content-Type: text/html

<HTML><HEAD></HEAD>Message</BODY></HTML>
Php5 is compiled as module. Same result with php4.3.10 as cgi.
Thanks for any help! Martin
Jul 17 '05 #1
2 2833
Martin Kofahl <no@spam> wrote:
I'm slightly confused with the passthru() command. The program I call writes
html headers itself. However, passthru() makes apache sending some generated
headers first. There's no fault with spaches in the code etc, I think.
Here's an simplified example:
$ cat /www/example.php
<?
passthru("cat /tmp/output");
?>


http://nl3.php.net/passthru
"passthru -- Execute an external program and display raw output"

In PHP's context output is http body, http headers can be set with
headers.

Couple of possibilities:
-tell/make the program not to output it's own headers
-call the program directly as a cgi
-suppress php's header generation
-have php filter the output and extract the headers

The last one might be most approriate:
just read the output (popen/fopen) line line by line. Everything till
the first blank line are headers, so output them using header().
Everything after that is the body and could be sent to the client with
echo.

Jul 17 '05 #2
Hi Daniel,
I got it using the following codesnip.

unset($output);
$pipe = popen("/usr/local/bin/mapserv", "r");
while(!feof($pi pe) and !($output === "\n")) {
$output = fgetss($pipe);

if (!($output === "\n"))
header($output) ;
}
fpassthru($pipe );
pclose($pipe);

Thank you!
Martin
Jul 17 '05 #3

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

Similar topics

2
2489
by: Kevin Thorpe | last post by:
I have a problem with IE and generated images (jpgraph). It displays them fine but it's not printing them. They appear as little red crosses in print preview. I've fiddled with the cache control headers as I thought that was it. Certainly IE refuses to cache pdf files sent using fpassthru and cannot open them in acrobat. Any suggestions...
0
2206
by: Yemi | last post by:
Hi There. I seem to be getting some inconsistent results when using passthru() in safe mode. They appear to be related to the fact that passthru should treat all command arguments as one single argument when safe mode is on. Everything works just fine on my MacOS X webserver ( Apache 1.3.29 with PHP 4.3.6 ). But on my Linux Enterprise 3.0...
3
3380
by: Jerry | last post by:
I've found a problem with exec, passthru, shell_exec & system. I'm trying to run the following exec("sort -r -n -k2,2 r1.txt > r2.txt") with r1.txt being a numeric file. The file looks like this: 237 291 845 152 585 3 193 810 173 484 151 3
2
5273
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each time. The transcript so far is reproduced for your amusement below. To summarise: I've put up a Sudoku-solving program called Sudoku.exe. I...
0
1665
by: Steve Barker | last post by:
Hi guys! In Visual Studio .NET, I like to enable auto-generation of XML documentation on the project properties screen, by adding an XML file name under "Configuration Properties" --> "Build" --> "XML Documentation File". This way, I get warnings in the task list about public methods I have written that do not have XML comments (launched by...
3
1315
by: Adel | last post by:
Hello. Is the statement below proved by the ANSI C standard? "It is undesirable to use explicitly sized variables in functions as auto variables or parameters. The values will always be stored as the processor native word size, and extra code will be generated by the compiler to mask off bits that are not significant in the result." Adel
6
5057
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which...
0
1551
by: Viorel | last post by:
Working as a beginner with data objects in Visual Studio 2003 and C#, I use the "Generate Dataset" command in order to generate automatically the dataset objects based on data adapters. Generated objects offer a convenient way of working with database fields. For instance, if a database table contains a "quantity" column, then, in the program,...
3
1832
by: Heiko Milke | last post by:
When working with Visual Studio 2003 it sometimes happens that auto-generated code gets lost. I have an .aspx page with its parental c# codebehind page. When creating a webform using the studio there is a section for auto-generated code. Within this region there is a function "InitializeComponent" that also registers all event handlers for...
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8204
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.