Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The BR from the twilight zone

Status
Not open for further replies.

OsakaWebbie

Programmer
Joined
Feb 11, 2003
Messages
628
Location
JP
I have a set of PHP files that always start with a couple includes - the first defines some functions and establishes a database connection, and the second uses sessions to authenticate the user. Everything worked fine on my local machine, running Apache/PHP/MySQL on Windows and using Shift-JIS as the character set to encode Japanese text. I uploaded the whole thing to a web hoster who is running MySQL with UTF-8, so I converted the database data and changed the page header to specify UTF-8, and most things were working fine. But I have one PHP source file that has a little bit of Japanese text in it, and today I learned that I can open it in Notepad and do Save As, specifying UTF-8, to convert the text. I did that, and uploaded the new file. But for some mysterious reason, now some text is sent to the browser before my early code runs - to be exact, &quot;<br />&quot; and a carriage return. Naturally my session code complains that the headers are already sent. I didn't change anything in my code, the source and the two included files all start immediately with &quot;<?php&quot;, and I don't even have any instances of &quot;<br />&quot; anywhere in my files (I'm still using plain &quot;<br>&quot; - please don't lecture me about that). So I don't know where that text is coming from - does anyone else have a clue? I don't know whether it's relevent, but the file in question is called inside an iframe of another file.
 
Update: I was mistaken about what text was being sent to mess it up - the &quot;<br />&quot; was the beginning of the error message about the headers already having been sent. So whatever is causing the headers to be sent is invisible in the browser's View Source, not a BR tag. Any thoughts?
 
maybe a blank line or a space in that include file...blanks are sent to the browser and really won't show anything, but it will cause the header error

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Nope - the first characters are &quot;<?php&quot; and the last are &quot;?>&quot;. Plus, the include files were not changed, and they work fine in all other pages in the site. The only one with a problem is the page whose code was saved as UTF-8 using Notepad. I'm aware that most of you out there aren't dealing with multibyte text, so have never changed the encoding in Notepad, but I'm hoping someone has an idea, or at least can tell me how I can look for the problem. When I look at View Source, the very first thing I see (no blank lines, no spaces) is the html generated for the header error message.
 
After no response for a while, I put some more time into the research, and finally found some clues (discussions on other forums which showed up in web searches). Here are the relevent pieces of two posts I found useful:
(1) You can use notepad Save As.... UPF-8, but it's not good, because it sends out the signature, and it happens before you can send any headers, sessions, cookies etc....
Microsoft Developer Studio does right job. - Advanced Save Options - utf8-without signature.

(2) ...but I had to resort to using notepad to do the 'save as utf-8' step, and then use a different program (cygwin's vi) to remove the four or five bytes which were mangling the header line.


I don't have Microsoft Developer Studio, but these two posts gave me the idea to log onto the hoster with ssh and look at the uploaded file with vi, since Notepad was showing me nothing I could see. Lo and behold, I found three characters at the beginning of my file: \xef\xbb\xbf. I have no idea what they are supposed to do, but the one post refers to them as the &quot;signature&quot;. Anyway, I removed them, and all is well. I hope this helps someone else. And if someone can tell me what a file signature is, I can be smarter the next time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top