PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html 
Author Message
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

In another thread, this problem was mentioned; but it was off-topic for that
thread.

Background:

Adobe Acrobat supports a "submit" method for the FDF which can be either FDF
or HTML (url-encoded form data). In cases where no processing/parsing of the
form data is needed, the FDF submittal method is sometimes used.

Ideally, it would be nice if one could simply echo the FDF submittal back to
the client browser, e.g.,

<?php echo $HTTP_RAW_POST_DATA; ?>

This strategy does not work, however, because the default behavior of PHP4
appears to be to issue the Content-Type: text/html immediately on
encountering the <?php token.

Even though FDF data is plain text, it is mis-interpreted if it is presented
to the browser as HTML. This problem can be easily fixed by enclosing the
FDF in <pre> tags, e.g.,

<?php echo "<pre>$HTTP_RAW_POST_DATA</pre>"; ?>

This works as intended, preventing the browser from interpreting any of the
FDF as HTML, while allowing the user to save the FDF that is displayed in
the browser for later reuse.

Problem: How to add Content-Length: header

While the above strategy works for small FDF submittals, there are instances
where large data sets are truncated by MSIE, which truncation corrupts the
FDF so that it is not repairable. MSIE does not do this trucation if the
correct Content-Length header is transmitted along with the Content-Type:
header.

In Perl, this problem is easily overcome by delaying the issuance of
Content-Type:, ..., headers until after the length of the data to be
transmitted is determined. Attempts to do likewise with PHP4 are frustrated
by the above-described immediate issuance of Content-Type: text/html.

Desired Solutions:

With Perl, this problem is easily solved without the use of any toolkits or
modules. A similar solution for the same problem with PHP4 is desired.

Any ideas?

Cheers.

Bill Segraves



Tue, 21 Jun 2005 02:21:09 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

[snip]

Quote:
> In Perl, this problem is easily overcome by delaying the issuance of
> Content-Type:, ..., headers until after the length of the data to be
> transmitted is determined. Attempts to do likewise with PHP4 are frustrated
> by the above-described immediate issuance of Content-Type: text/html.

> Desired Solutions:

> With Perl, this problem is easily solved without the use of any toolkits or
> modules. A similar solution for the same problem with PHP4 is desired.

http://www.php.net/manual/en/function.ob-get-length.php

In the usernotes is an example that fits your needs exactly IMHO.

--

  Daniel Tryba



Tue, 21 Jun 2005 02:36:05 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

<snip>

Quote:
> http://www.php.net/manual/en/function.ob-get-length.php

> In the usernotes is an example that fits your needs exactly IMHO.

Thanks, Daniel. I'll give that a try.

Cheers.

Bill Segraves



Tue, 21 Jun 2005 04:22:50 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

<snip>

Quote:
> http://www.php.net/manual/en/function.ob-get-length.php

> In the usernotes is an example that fits your needs exactly IMHO.

Daniel, I presume you're referring to this example:

"webmaster at crescentart dot com
29-Jun-2001 02:58

Here is an easy way to get the header Content-Lenght.
<?
ob_start();
?>

Put HTML tags.

<?
$size=ob_get_length();
header("Content-Length: $size");
ob_end_flush();
?>
"

for which I get the dreaded

Warning: Cannot add header information - headers already sent by (output
started at c:\INDIGO~1\PHP\FDF_BO~1.PHP:2) in c:\INDIGO~1\PHP\FDF_BO~1.PHP
on line 13

This is the problem I've been seeing with Win32, PHP4 (v. 4.2.3), and
Apache. I've noted in the documentation that PHP4 emits HTML by default; but
just don't know if it can be changed, if at all.

If there's no PHP4-supported solution, this is a problem for anyone who is
considering use of PHP.

For me, it's not a big deal, as the solution I posted earlier, i.e.,

<?php echo "<pre>$HTTP_RAW_POST_DATA</pre>"; ?>

works fine. I just strip off the <pre> tags on the client-side with a regex.

Cheers.

Bill Segraves



Tue, 21 Jun 2005 05:01:57 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

Quote:
>> http://www.php.net/manual/en/function.ob-get-length.php

> Here is an easy way to get the header Content-Lenght.
> <?
> ob_start();
> ?>

> Put HTML tags.

> <?
> $size=ob_get_length();
> header("Content-Length: $size");
> ob_end_flush();
> ?>
> "

> for which I get the dreaded

> Warning: Cannot add header information - headers already sent by (output
> started at c:\INDIGO~1\PHP\FDF_BO~1.PHP:2) in c:\INDIGO~1\PHP\FDF_BO~1.PHP
> on line 13

Show us your (relevant) code (in this case atleast line 2-13), or use
the exact example given on the man page.

Quote:
> This is the problem I've been seeing with Win32, PHP4 (v. 4.2.3), and
> Apache.

This shouldn't be a problem, if it is, the php version you are using is
horribly broken (I guess) and you should either upgrade or downgrade to
a working version.

Quote:
> I've noted in the documentation that PHP4 emits HTML by default; but
> just don't know if it can be changed, if at all.

text/html is the default content-type, with
'header("Content-Type: mime/type");' you can change it to anything you
would like/need. So I get what's your problem!

--

  Daniel Tryba



Tue, 21 Jun 2005 05:44:24 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

<snip>

Quote:
> Show us your (relevant) code (in this case atleast line 2-13), or use
> the exact example given on the man page.

O.K. Here's the code from the ob_get_length example:

#!c:\php\php
<?
ob_start();
?>

Put HTML tags.

<?
$size=ob_get_length();
header("Content-Length: $size");
ob_end_flush();
?>

Quote:
> > This is the problem I've been seeing with Win32, PHP4 (v. 4.2.3), and
> > Apache.

> This shouldn't be a problem, if it is, the php version you are using is
> horribly broken (I guess) and you should either upgrade or downgrade to
> a working version.

I think 4.2.3 was the latest available at the time I downloaded it.

Quote:
> > I've noted in the documentation that PHP4 emits HTML by default; but
> > just don't know if it can be changed, if at all.

> text/html is the default content-type, with
> 'header("Content-Type: mime/type");' you can change it to anything you
> would like/need. So I get what's your problem!

Yes. That's the problem. It works fine if my PHP script is emitting HTML,
and there is no requirement for Content-Length or other Content-XXXX
headers. Once PHP has emitted a Content-Type: text/html header and the
mandatory blank line to end the headers, no more headers should be possible.
Here's the output from the above script:

Put HTML tags.
Warning: Cannot add header information - headers already sent by (output
started at c:\INDIGO~1\PHP\OB_GET~1.PHP:2) in c:\INDIGO~1\PHP\OB_GET~1.PHP
on line 10

Thanks for your help, Daniel. AFAICT, PHP4 is steadfastly doing what it is
supposed to do for the client, i.e., output HTML, period.

Cheers.

Bill Segraves



Tue, 21 Jun 2005 07:25:31 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

Quote:
> O.K. Here's the code from the ob_get_length example:

> #!c:\php\php
> <?
> ob_start();
> ?>

> Put HTML tags.

> <?
> $size=ob_get_length();
> header("Content-Length: $size");
> ob_end_flush();
> ?>

Hmmmm, using the cgi version on my system the result is:
---
X-Powered-By: PHP/4.2.3
Content-Length: 17
Content-type: text/html

Put HTML tags.

---

This being a Linux system sothat EOLs are 1 character, the code works
perfectly.

But for you the output is:

Quote:
> Here's the output from the above script:

> Put HTML tags.
> Warning: Cannot add header information - headers already sent by (output
> started at c:\INDIGO~1\PHP\OB_GET~1.PHP:2) in c:\INDIGO~1\PHP\OB_GET~1.PHP
> on line 10

> Thanks for your help, Daniel. AFAICT, PHP4 is steadfastly doing what it is
> supposed to do for the client, i.e., output HTML, period.

My guess is that there is something wrong with your cgi binary, sorry
but I don't think I can help you any further with this problem. You
could/should try 4.3.0 (install it in a different location to test), or
check if someone else reported a bug for php4.2.3/win32 like yours.

--

  Daniel Tryba



Tue, 21 Jun 2005 07:54:36 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

<snip>

Quote:
> Hmmmm, using the cgi version on my system the result is:
> ---
> X-Powered-By: PHP/4.2.3
> Content-Length: 17
> Content-type: text/html

> Put HTML tags.

> ---

> This being a Linux system sothat EOLs are 1 character, the code works
> perfectly.

Well, that's encouraging. What's your shebang line on your version of the
script? Something like

#!/usr/bin/php

where php is a symlink to the php4 executable?

At least, it appears this is not a problem with PHP4, in general, but
perhaps something afoul in the PHP4, v. 4.2.3 Win32 binary.

I really do appreciate your help. As my target system is a Linux system,
There appears to be strong evidence supporting correct operation with Linux.

Quote:
> But for you the output is:
> > Here's the output from the above script:

> > Put HTML tags.
> > Warning: Cannot add header information - headers already sent by (output
> > started at c:\INDIGO~1\PHP\OB_GET~1.PHP:2) in

c:\INDIGO~1\PHP\OB_GET~1.PHP

Quote:
> > on line 10

> > Thanks for your help, Daniel. AFAICT, PHP4 is steadfastly doing what it
is
> > supposed to do for the client, i.e., output HTML, period.

When I crunched all of the lines down to the minimum, i.e.,

#!c:\php\php
<?ob_start();?>
Put HTML tags.
<? $size=ob_get_length(); header("Content-Length: $size"); ob_end_flush();
?>

the results were similar, e.g., line number for the warning was line 4.

Quote:
> My guess is that there is something wrong with your cgi binary, sorry
> but I don't think I can help you any further with this problem. You
> could/should try 4.3.0 (install it in a different location to test), or
> check if someone else reported a bug for php4.2.3/win32 like yours.

Will do. Or just jump over to the Linux system on the same network, skipping
Win32 implementation completely.

Thanks again for your help.

Cheers.

Bill Segraves



Tue, 21 Jun 2005 08:14:34 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html


Quote:


> <snip>
> > Hmmmm, using the cgi version on my system the result is:
> > ---
> > X-Powered-By: PHP/4.2.3
> > Content-Length: 17
> > Content-type: text/html

> > Put HTML tags.

From the command line, I got the same messages, with the warnings appearing
after the above.

Digging deeper in the configuration, I found the default output buffering in
the php.ini file for the Win32 binary is

output_buffering=Off

Changing the output buffering to

output_buffering=On

fixes the problem.

Thanks again, Daniel, for your help.

Cheers.

Bill Segraves



Tue, 21 Jun 2005 09:25:06 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

[OB/header troubles]

Quote:
> Digging deeper in the configuration, I found the default output buffering in
> the php.ini file for the Win32 binary is

> output_buffering=Off

> Changing the output buffering to

> output_buffering=On

> fixes the problem.

Hmmmm, the problem should'nt exist in the first plae, but nie to know
there is a work around :)

--

  Daniel Tryba



Wed, 22 Jun 2005 06:33:01 GMT  
 PHP, PDF, and FDF - problem with PHP4 default Content-Type: text/html

Quote:

> [OB/header troubles]
> > Digging deeper in the configuration, I found the default output
buffering in
> > the php.ini file for the Win32 binary is

<snip>

Quote:
> > Changing the output buffering to

> > output_buffering=On

> > fixes the problem.

> Hmmmm, the problem should'nt exist in the first plae, but nie to know
> there is a work around :)

In the M$ world, it would be called a feature. The "output_buffering=Off"
feature enable Windows to cripple PHP so all it can emit is HTML and error
messages. ;-)

Cheers.

Bill Segraves



Wed, 22 Jun 2005 07:15:58 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. extract info from pdf doc,PDF to XML, HTML

2. Content-Type: text/plain; charset=us-ascii

3. Content-Type: text/plain; charset=iso-8859-1

4. Content-Type: text/plain;

5. Content-Type: text/plain;

6. ANNOUNCE: IndexMaker 6.7: an index.html maker from PDF,HTML,VRML and other files

7. ANNOUNCE: IndexMaker 6.6: an index.html maker from PDF,HTML,VRML and other files

8. ANNOUNCE: IndexMaker 6.5: an index.html maker from PDF,HTML,VRML and other files

9. ANNOUNCE: IndexMaker 6.1: an index.html maker from PDF,HTML,VRML and other files

10. ANNOUNCE: IndexMaker 6.0: an index.html maker from PDF,HTML,VRML and other files

11. ANNOUNCE: IndexMaker 5.3: an index.html maker from PDF,HTML,VRML and other files

12. ANNOUNCE: IndexMaker 5.2: an index.html maker from PDF,HTML,VRML and other files

 

 
Powered by phpBB® Forum Software