Connecting Tech Pros Worldwide Help | Site Map

utf-8 pages and php 4.1.1

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 22nd, 2005, 12:45 PM
Jan Wagner
Guest
 
Posts: n/a
Default utf-8 pages and php 4.1.1

Hi,

I'm running into a problem with php 4.1.1 on IIS (XP Pro version).
For example writing a page test.php that starts with

<?php session_start(); ?>
<?php echo '<?xml version="1.0"'; ?>
<?php echo ' encoding="utf-8" ?>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en"><!-- InstanceBegin template="/Templates/stdPage.dwt"
codeOutsideHTMLIsLocked="true" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
....

and saving the test.php in UTF-8 format in UltraEdit-32 or SciTE,
then running the page, there's a complaint for session_start() about
headers/page data having already been sent. If the same page is
saved as "plain" ASCII, it works. Any ideas how to get an UTF-8
encoded page to work in php 4.1.1, without upgrading?

thanks,
- Jan

  #2  
Old August 22nd, 2005, 02:35 PM
JDS
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

On Mon, 22 Aug 2005 15:35:48 +0300, Jan Wagner wrote:
[color=blue]
> I'm running into a problem with php 4.1.1 on IIS (XP Pro version).[/color]

Upgrade immediately!! Upgrade PHP, that is. Not for functionality
reasons; for security reasons. You have been warned.

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

  #3  
Old August 22nd, 2005, 04:25 PM
Jan Wagner
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

JDS wrote:[color=blue]
> On Mon, 22 Aug 2005 15:35:48 +0300, Jan Wagner wrote:[color=green]
>>I'm running into a problem with php 4.1.1 on IIS (XP Pro version).[/color]
>
> Upgrade immediately!! Upgrade PHP, that is. Not for functionality
> reasons; for security reasons. You have been warned.[/color]

Unfortunately I'm not the admin, and upgrading to PHP 5.0.3 for
Novell might break some of the hosted sites. I'd have liked
Tomcat/JSP instead of a vulnerability ridden PHP interpreter anyway,
but Tomcat 4/5 won't run on NW5.

However, my devel machine I now upgraded 5.0.4, to check. Oddly I
still get the same session warnings for UTF-8 files:

Warning: session_start() [function.session-start]: Cannot send
session cookie - headers already sent by (output started at
c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php:1) in
c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php on line 1

Warning: session_start() [function.session-start]: Cannot send
session cache limiter - headers already sent (output started at
c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php:1) in
c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php on line 1

and the line 1 is <?php session_start(); ?>

When I convert the php to 8-bit ascii the warnings disappear.
Probably not a bug but a wrong setting somewhere? Or, other way
round, is anyone using UTF-8 encoded .php files and it is working
fine for them? Required changing something in php.ini?

- Jan
  #4  
Old August 22nd, 2005, 05:05 PM
JDS
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

On Mon, 22 Aug 2005 19:16:48 +0300, Jan Wagner wrote:
[color=blue]
> Unfortunately I'm not the admin, and upgrading to PHP 5.0.3 for
> Novell might break some of the hosted sites. I'd have liked
> Tomcat/JSP instead of a vulnerability ridden PHP interpreter anyway,
> but Tomcat 4/5 won't run on NW5.[/color]

I didn't say upgrade to PHP5. Update to PHP 4.4. That should prevent
most breakages and improve security.

Unfortunately, I really don't have an answer regarding your UTF problems.
Sorry.

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

  #5  
Old August 22nd, 2005, 06:35 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

On Mon, 22 Aug 2005 15:35:48 +0300, Jan Wagner <no_spam@thanks.net> wrote:
[color=blue]
>I'm running into a problem with php 4.1.1 on IIS (XP Pro version).
>For example writing a page test.php that starts with
>
><?php session_start(); ?>
>
>and saving the test.php in UTF-8 format in UltraEdit-32 or SciTE,
>then running the page, there's a complaint for session_start() about
>headers/page data having already been sent. If the same page is
>saved as "plain" ASCII, it works. Any ideas how to get an UTF-8
>encoded page to work in php 4.1.1, without upgrading?[/color]

Odds are you have a UTF-8 BOM (Byte Order Marker) at the start of the script.

In Ultraedit:

Advanced, Configuration, General tab,
Scroll to "Load/Save Conversions"
Disable the two "Write UTF-8 BOM" options.

http://bugs.php.net/bug.php?id=22108 appears to indicate that UTF-8 encoded
PHP scripts with a leading BOM is basically not supported, for reasonable
reasons (it can't tell if it's a BOM to ignore, a BOM that should be sent, or
actually some binary data that happens to look like a BOM).

Since you can always save it without a BOM that's not too bad.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
  #6  
Old August 22nd, 2005, 06:45 PM
Gordon Burditt
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

>However, my devel machine I now upgraded 5.0.4, to check. Oddly I[color=blue]
>still get the same session warnings for UTF-8 files:
>
>Warning: session_start() [function.session-start]: Cannot send
>session cookie - headers already sent by (output started at
>c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php:1) in
>c:\Inetpub\wwwroot\spraknat\Kultur-GDolivo-text.php on line 1[/color]

You may not output *ANYTHING* before the headers. Not
a blank line. Not a single space. Not a UTF-8 marker
that says it's UTF-8.
[color=blue]
>and the line 1 is <?php session_start(); ?>[/color]

And what's before the <? on line 1? Dump your file in hex
to be sure.

Gordon L. Burditt
  #7  
Old August 22nd, 2005, 06:55 PM
Jan Wagner
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1

JDS wrote:[color=blue]
> On Mon, 22 Aug 2005 19:16:48 +0300, Jan Wagner wrote:[color=green]
>>Unfortunately I'm not the admin, and upgrading to PHP 5.0.3 for
>>Novell might break some of the hosted sites. I'd have liked
>>Tomcat/JSP instead of a vulnerability ridden PHP interpreter anyway,
>>but Tomcat 4/5 won't run on NW5.[/color]
>
> I didn't say upgrade to PHP5. Update to PHP 4.4. That should prevent
> most breakages and improve security.[/color]

Ok thanks! I'll suggest it to the admin (although the newest php4
for netware is 4.2.3 and not 4.4.0, but I suppose that's still
better than 4.1.1 :)
[color=blue]
> Unfortunately, I really don't have an answer regarding your UTF problems.
> Sorry.[/color]

Found it myself after more digging... Bug #22108,
http://bugs.php.net/bug.php?id=22108, solution included in php 5 cvs
but not enabled per default in the win32 release. "This will come
with Unicode support in PHP 6.0". So looks like until then, no
unicode support in win32 (unless you recompile php5), and all code
and pages must remain "plain" ASCII. Apparently same thing for
netware. Well well...

thanks,
- Jan
  #8  
Old August 22nd, 2005, 07:05 PM
Jan Wagner
Guest
 
Posts: n/a
Default Re: utf-8 pages and php 4.1.1


(I did not refresh and see this before my prev posting...)

Andy Hassall wrote:[color=blue]
> On Mon, 22 Aug 2005 15:35:48 +0300, Jan Wagner <no_spam@thanks.net> wrote:
> Odds are you have a UTF-8 BOM (Byte Order Marker) at the start of the script.
>
> In Ultraedit:
>
> Advanced, Configuration, General tab,
> Scroll to "Load/Save Conversions"
> Disable the two "Write UTF-8 BOM" options.[/color]

Yes, that works! Good workaround - thanks! :)

- Jan
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.