Warning “headers already sent by” while developing PHP webapp

22 May

What are headers?

Every time you respond a request, there are some information attached at the beginning of the response. Those are headers. For example:

HTTP/1.1 200 OK
Date: Wed, 08 Feb 2006 08:20:07 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) mod_auth_pgsql/2.0.2b1 mod_ssl/2.0.54 OpenSSL/0.9.7e
X-Powered-By: PHP/4.4.0
Transfer-Encoding: chunked
Content-Type: text/html

Those headers is used to control the browser behaviors such as caching, rendering… If you want to learn more about how to use them, you can see more helps and instructions from here:

http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html

Why do I get this warning?

Sometimes, you receive the warnings like this: “… headers already sent by”. It’s also mentioned in that article, but I will summarize the reason here. You got that warning because you call a function like header() or session_start() after sending page content. The page content includes what you sent to browser by echo, print, or whatever outside the server tag <? … ?>. Be caution: the headers must be sent before any other responses.

But actually I did not send any page content before calling header function? Why the warnings are still there?

This is one of the stupid bugs that PHP developers usually get. The page content includes ANY THINGS outside the server tags <? … ?>, that means white spaces and new line characters are also counted as well. Check your code again, maybe you left some blanks after the ending tag ?> in one of your included file.

Ah, one more thing! When you save your files as “UTF-8 with signature” on Windows platforms, 3 bytes with hex code “EFBBBF” will be inserted automatically at the beginning of the files. Those bytes are used to let Windows regconize that the file contains UTF-8 text. They’re unneeded in PHP because PHP won’t treat this signature. It considers those bytes as page content because they appear before the opening tag <?. As the result, any calling to header() and session_start() will be failed. If you’re using Zend Studio, choose the Encoding to “UTF-8 without signature” when saving.

Permission denied when using MSMQ

8 Apr

You want to develop an application using MSMQ service, but whenever you send or receive message from MSMQ, you receive a Permission Denied exception. A possible reason is that you may have installed MSMQ in workgroup mode.

You can find the resolution for this problem here: http://support.microsoft.com/kb/247394/EN-US/

To use queued components in Workgroup mode, you must do two things:

  • To allow for unsigned MSMQ messages, you must set the Authentication Level of the COM+ Application to None.
  • To access the queued components from a remote computer, you must specify a queue: moniker that contains the complete FormatName of the destination queue.

To change the Authentication Level of the COM+ Application that hosts the queued components, perform the following steps:

  1. Under Administrative Tools, open the Component Services MMC snap-in.
  2. Expand My Computer and browse to the COM+ Application that hosts the queued components.
  3. To open the property sheet for the application, right-click the application and select Properties. Click the Security tab, and select None for Authentication level for calls.

Fade effect in IE

22 Nov

To add a fade effect to your webpage, you just include this line on the top of your page:

<META http-equiv=Page-Enter content=blendtrans(duration=0.1);>

Unfortunately, it’s supported only by IE.

Migrating UTF8 data from MySQL 5.0 to 4.x (with latin charset)

27 Sep

Some of old PHP application use ANSI SQL to create table and insert data. So when I use those application with UTF8 content in MySQL 5.0, the default character-set of those table is latin1. The problems come when I want to move data to an older MySQL, the encoded content goes wrong.

So this is the solution:

mysqldump -u username –opt –default-character-set=latin1 –skip-set-charset –skip-tz-utc –skip-comments –single-transaction %1 %2 %3 %4 %5

This post will be updated later with full description.

Thử làm cái test coi sao

7 Sep
You scored as Neo, the “One”. Neo is the computer hacker-turned-Messiah of the Matrix. He leads a small group of human rebels against the technology that controls them. Neo doubts his ability to lead but doesn’t want to disappoint his friends. His goal is for a world where all men know the Truth and are free from the bonds of the Matrix.

Neo, the “One”
75%
The Amazing Spider-Man
58%
Maximus
54%
The Terminator
54%
Lara Croft
46%
Indiana Jones
46%
Batman, the Dark Knight
38%
Captain Jack Sparrow
33%
El Zorro
29%
William Wallace
29%
James Bond, Agent 007
21%

Which Action Hero Would You Be? v. 2.0
created with QuizFarm.com

Reading: Làm lập trình viên hay không làm lập trình viên

20 Jul

http://blog.360.yahoo.com/blog-iveB6n89cqh0zy5ZuFiCuQ–?cq=1&p=1&n=28500

(tác giả: Lê Đình Lĩnh Nam)

Được nghỉ 3 ngày nên ngồi suy ngẫm về cái nghiệp lập trình viên mà mình đang theo đuổi. Image Continue reading

text-align bug in FireFox 1.5

19 Jul

While I am rendering a CSS theme for my webapp, I see this problem:

.container{
text-align: center;
border: solid 1px blue;
}
<div class=container><table><tr><td>Text</td></tr></table><div>

In theory, we will have a center-aligned table, and it worked in IE6, but not in Firefox 1.5. If I add align into the div tag, it worked in both. After struggling with a sea of CSS references, trying to find out some other way to work arround this bug, I finally found this:

http://geekswithblogs.net/timh/archive/2006/04/19/75606.aspx

So this is my solution:
.container{
text-align: center;
border: solid 1px blue;
}

.container{
text-align:-moz-center;
}

Just place those lines into your CSS, the browser will automatically choose the best. Note: never place 2 text-align in 1 block.

Similarly, if you want to right-align the table box, use -moz-right.

Another trick to center the table:

.container{
text-align: center;
border: solid 1px blue;
}
.container table{
margin:0px auto;
}

I don’t find any other trick for right-aligning.

Follow

Get every new post delivered to your Inbox.